fixi 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/LICENSE +203 -0
- data/README.md +170 -0
- data/Rakefile +8 -0
- data/bin/fixi +15 -8
- data/fixi.gemspec +3 -4
- data/lib/fixi/command/add.rb +5 -2
- data/lib/fixi/command/bag.rb +94 -0
- data/lib/fixi/command/check.rb +17 -4
- data/lib/fixi/command/commit.rb +5 -2
- data/lib/fixi/command/info.rb +5 -2
- data/lib/fixi/command/init.rb +4 -0
- data/lib/fixi/command/ls.rb +5 -2
- data/lib/fixi/command/rm.rb +5 -2
- data/lib/fixi/command/sum.rb +5 -1
- data/lib/fixi/command/unbag.rb +124 -0
- data/lib/fixi/command.rb +4 -3
- data/lib/fixi/index.rb +24 -18
- data/lib/fixi/version.rb +1 -1
- data/lib/fixi.rb +12 -0
- data/spec/lib/fixi/command/init_spec.rb +29 -0
- data/spec/lib/fixi/patch/string_pack_spec.rb +15 -0
- data/spec/lib/fixi_spec.rb +47 -0
- data/spec/spec_helper.rb +27 -0
- metadata +41 -9
- data/README +0 -19
data/.gitignore
CHANGED
data/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
Fixi is a command-line utility, written in Ruby, that indexes, verifies, and
|
|
4
|
+
updates checksum information for collections of files.
|
|
5
|
+
|
|
6
|
+
Tracking fixity is an important part of any digital preservation strategy,
|
|
7
|
+
and fixi aims to help with that in as unobtrusive a manner as possible.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
* Works with any pre-existing directory layout scheme.
|
|
12
|
+
* Keeps the index in a single ".fixi" directory at the root of the collection
|
|
13
|
+
* Supports regular expression-based includes and excludes
|
|
14
|
+
* Supports any combination of md5, sha1, sha256, sha384, and sha512
|
|
15
|
+
* Supports shallow (fast) and deep (checksum-based) fixity checking
|
|
16
|
+
* Support export and import of BagIt bags
|
|
17
|
+
* Supports fast lookups of files by checksum
|
|
18
|
+
|
|
19
|
+
# Installation
|
|
20
|
+
|
|
21
|
+
Releases of Fixi are published to rubygems.org, so you can install them the
|
|
22
|
+
usual way:
|
|
23
|
+
|
|
24
|
+
[sudo] gem install fixi
|
|
25
|
+
|
|
26
|
+
Or you can install from source via:
|
|
27
|
+
|
|
28
|
+
[sudo] rake install
|
|
29
|
+
|
|
30
|
+
*NOTE: Fixi uses sqlite3, which will need to be built if it's not already on
|
|
31
|
+
your system.*
|
|
32
|
+
|
|
33
|
+
If you are using Ubuntu and you get an error about building sqlite, you may
|
|
34
|
+
need to install both the ruby1.9.1-dev and the libsqlite3-dev packages:
|
|
35
|
+
|
|
36
|
+
[sudo] apt-get install ruby1.9.1-dev libsqlite3-dev
|
|
37
|
+
|
|
38
|
+
Similar steps may be necessary for other distros and operating systems.
|
|
39
|
+
|
|
40
|
+
# General Usage
|
|
41
|
+
fixi [--version] [--help] <command> [<options>] [<args>]
|
|
42
|
+
|
|
43
|
+
## Global Options:
|
|
44
|
+
--version, -v: Display the version and exit.
|
|
45
|
+
--help, -h: Show general or command-specific help
|
|
46
|
+
|
|
47
|
+
See below for command-specific usage and options.
|
|
48
|
+
|
|
49
|
+
# add: Add new files to the index
|
|
50
|
+
|
|
51
|
+
## Usage:
|
|
52
|
+
fixi add [<options>] [<dir> | <file>]
|
|
53
|
+
|
|
54
|
+
## Options:
|
|
55
|
+
--absolute, -a: Show absolute paths. By default, paths are reported
|
|
56
|
+
relative to the index root.
|
|
57
|
+
--dry-run, -d: Don't do anything; just report what would be done
|
|
58
|
+
|
|
59
|
+
# bag: Export files as a new BagIt bag
|
|
60
|
+
|
|
61
|
+
## Usage:
|
|
62
|
+
fixi bag [<options>] <input-dir> <output-dir>
|
|
63
|
+
|
|
64
|
+
## Where:
|
|
65
|
+
input-dir is an indexed directory whose content should be exported.
|
|
66
|
+
output-dir is the base directory of the bag to be created.
|
|
67
|
+
|
|
68
|
+
## Options:
|
|
69
|
+
--algorithms, -l <s>: Checksum algorithm(s) to use for the bag. This is a
|
|
70
|
+
comma-separated list, which may include md5, sha1,
|
|
71
|
+
sha256, sha384, sha512, and must be a subset of the
|
|
72
|
+
indexed algorithms. If unspecified, manifests will be
|
|
73
|
+
created for all indexed algorithms.
|
|
74
|
+
|
|
75
|
+
# check: Verify the fixity of files in the index
|
|
76
|
+
|
|
77
|
+
## Usage:
|
|
78
|
+
fixi check [<options>] [<dir> | <file>]
|
|
79
|
+
|
|
80
|
+
## Options:
|
|
81
|
+
--absolute, -a: Show absolute paths. By default, paths are reported
|
|
82
|
+
relative to the index root.
|
|
83
|
+
--shallow, -s: Do shallow comparisons when determining which files have
|
|
84
|
+
changed. If specified, only file sizes and mtimes will be
|
|
85
|
+
used. By default, checksums will also be computed and
|
|
86
|
+
compared if necessary.
|
|
87
|
+
--verbose, -v: For modified files, show which attribute changed. By
|
|
88
|
+
default, only the path is shown.
|
|
89
|
+
|
|
90
|
+
# commit: Commit modified files to the index
|
|
91
|
+
|
|
92
|
+
## Usage:
|
|
93
|
+
fixi commit [<options>] [<dir> | <file>]
|
|
94
|
+
|
|
95
|
+
## Options:
|
|
96
|
+
--absolute, -a: Show absolute paths. By default, paths are reported
|
|
97
|
+
relative to the index root.
|
|
98
|
+
--dry-run, -d: Don't do anything; just report what would be done
|
|
99
|
+
--shallow, -s: Do shallow comparisons when determining which files have
|
|
100
|
+
changed. If specified, only file sizes and mtimes will be
|
|
101
|
+
used. By default, checksums will also be computed and
|
|
102
|
+
compared if necessary.
|
|
103
|
+
--verbose, -v: For modified files, show which attribute changed. By
|
|
104
|
+
default, only the path is shown.
|
|
105
|
+
|
|
106
|
+
# info: Display a summary of the index
|
|
107
|
+
|
|
108
|
+
## Usage:
|
|
109
|
+
fixi info [path]
|
|
110
|
+
|
|
111
|
+
# init: Create a new, empty index
|
|
112
|
+
|
|
113
|
+
## Usage:
|
|
114
|
+
fixi init [<options>] [<dir>]
|
|
115
|
+
|
|
116
|
+
## Options:
|
|
117
|
+
--algorithms, -l <s>: Checksum algorithm(s) to use for the index. This is
|
|
118
|
+
a comma-separated list, which may include md5, sha1,
|
|
119
|
+
sha256, sha384, and sha512. (Default: sha256)
|
|
120
|
+
|
|
121
|
+
# ls: List contents of the index
|
|
122
|
+
|
|
123
|
+
## Usage:
|
|
124
|
+
fixi ls [<options>] [<dir> | <file>]
|
|
125
|
+
|
|
126
|
+
## Options:
|
|
127
|
+
--absolute, -a: Show absolute paths. By default, paths are reported
|
|
128
|
+
relative to the index root.
|
|
129
|
+
--json, -j: Like --verbose, but outputs the result as a json array.
|
|
130
|
+
--md5 <s>: Restrict list to files with the given md5 checksum
|
|
131
|
+
--sha1 <s>: Restrict list to files with the given sha1 checksum
|
|
132
|
+
--sha256 <s>: Restrict list to files with the given sha256 checksum
|
|
133
|
+
--sha384 <s>: Restrict list to files with the given sha384 checksum
|
|
134
|
+
--sha512 <s>: Restrict list to files with the given sha512 checksum
|
|
135
|
+
--verbose, -v: Include all information known about each file. By default,
|
|
136
|
+
only paths will be listed.
|
|
137
|
+
|
|
138
|
+
# rm: Delete old files from the index
|
|
139
|
+
|
|
140
|
+
## Usage:
|
|
141
|
+
fixi rm [<options>] [<dir> | <file>]
|
|
142
|
+
|
|
143
|
+
## Options:
|
|
144
|
+
--absolute, -a: Show absolute paths. By default, paths are reported
|
|
145
|
+
relative to the index root.
|
|
146
|
+
--dry-run, -d: Don't do anything; just report what would be done
|
|
147
|
+
|
|
148
|
+
# sum: Calculate checksum(s) of a file
|
|
149
|
+
|
|
150
|
+
## Usage:
|
|
151
|
+
fixi sum [<options>] <file>
|
|
152
|
+
|
|
153
|
+
## Options:
|
|
154
|
+
--algorithms, -l <s>: Checksum algorithm(s) to use. This is a
|
|
155
|
+
comma-separated list, which may include md5, sha1,
|
|
156
|
+
sha256, sha384, and sha512. At least one must be
|
|
157
|
+
specified.
|
|
158
|
+
|
|
159
|
+
# unbag: Import files from a BagIt bag
|
|
160
|
+
|
|
161
|
+
## Usage:
|
|
162
|
+
fixi unbag [<options>] <input-dir> <output-dir>
|
|
163
|
+
|
|
164
|
+
## Where:
|
|
165
|
+
input-dir is the base directory of the bag.
|
|
166
|
+
output-dir is the directory in which to import it.
|
|
167
|
+
|
|
168
|
+
## Options:
|
|
169
|
+
--absolute, -a: Show absolute paths. By default, paths are reported
|
|
170
|
+
relative to the index root.
|
data/Rakefile
CHANGED
data/bin/fixi
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
require 'rubygems'
|
|
4
|
-
require 'trollop'
|
|
5
4
|
require 'fixi'
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
name = ARGV.shift
|
|
10
|
-
if name.nil?
|
|
11
|
-
puts <<-EOS
|
|
6
|
+
def show_usage_and_exit
|
|
7
|
+
puts <<-EOS
|
|
12
8
|
usage: fixi [--version] [--help] <command> [<options>] [path]
|
|
13
9
|
|
|
14
10
|
All commands are scoped to the current directory or the given path, if specified.
|
|
15
11
|
|
|
16
12
|
Commands:
|
|
17
13
|
add: #{Fixi::Command::Add.synopsis}
|
|
14
|
+
bag: #{Fixi::Command::Bag.synopsis}
|
|
18
15
|
check: #{Fixi::Command::Check.synopsis}
|
|
19
16
|
commit: #{Fixi::Command::Commit.synopsis}
|
|
20
17
|
info: #{Fixi::Command::Info.synopsis}
|
|
@@ -22,16 +19,26 @@ Commands:
|
|
|
22
19
|
ls: #{Fixi::Command::Ls.synopsis}
|
|
23
20
|
rm: #{Fixi::Command::Rm.synopsis}
|
|
24
21
|
sum: #{Fixi::Command::Sum.synopsis}
|
|
22
|
+
unbag: #{Fixi::Command::Unbag.synopsis}
|
|
25
23
|
|
|
26
24
|
See 'fixi help <command>' for more information on a specific command.
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
EOS
|
|
26
|
+
exit 0
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
name = ARGV.shift
|
|
30
|
+
if name == "--help" || name == "-h" || name == "help"
|
|
31
|
+
name = ARGV.shift
|
|
32
|
+
if name.nil?
|
|
33
|
+
show_usage_and_exit
|
|
29
34
|
else
|
|
30
35
|
ARGV.insert(0, "--help")
|
|
31
36
|
end
|
|
32
37
|
elsif name == "--version" || name == "-v"
|
|
33
38
|
puts "fixi version #{Fixi::VERSION}"
|
|
34
39
|
exit 0
|
|
40
|
+
elsif name.nil?
|
|
41
|
+
show_usage_and_exit
|
|
35
42
|
end
|
|
36
43
|
|
|
37
44
|
command = Fixi::command name
|
data/fixi.gemspec
CHANGED
|
@@ -18,10 +18,9 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
19
|
s.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
|
21
|
+
s.add_development_dependency "rspec"
|
|
22
|
+
s.add_development_dependency "simplecov"
|
|
24
23
|
|
|
25
24
|
s.add_runtime_dependency "trollop"
|
|
26
|
-
s.add_runtime_dependency "sqlite3
|
|
25
|
+
s.add_runtime_dependency "sqlite3"
|
|
27
26
|
end
|
data/lib/fixi/command/add.rb
CHANGED
|
@@ -6,9 +6,12 @@ class Fixi::Command::Add
|
|
|
6
6
|
"Add new files to the index"
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def self.arghelp
|
|
10
|
+
"[<dir>|<file>]"
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
def self.details
|
|
10
|
-
"
|
|
11
|
-
if specified.".pack
|
|
14
|
+
"If no argument is given, the current directory ('.') is assumed."
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def execute args
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'trollop'
|
|
2
|
+
require 'fixi/index'
|
|
3
|
+
require 'set'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
|
|
6
|
+
class Fixi::Command::Bag
|
|
7
|
+
def self.synopsis
|
|
8
|
+
"Export files as a new BagIt bag"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.arghelp
|
|
12
|
+
"<input-dir> <output-dir>"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.details
|
|
16
|
+
"Where:\n input-dir is an indexed directory whose content should be exported.\n" +
|
|
17
|
+
" output-dir is the base directory of the bag to be created."
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def execute args
|
|
21
|
+
opts = Trollop::options args do
|
|
22
|
+
banner Fixi::Command.banner "bag"
|
|
23
|
+
opt :algorithms, "Checksum algorithm(s) to use for the bag. This is
|
|
24
|
+
a comma-separated list, which may include md5, sha1, sha256, sha384,
|
|
25
|
+
sha512, and must be a subset of the indexed algorithms. If unspecified,
|
|
26
|
+
manifests will be created for all indexed algorithms.".pack,
|
|
27
|
+
:short => 'l', :type => :string
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
raise "Must specify input directory." unless args[0]
|
|
31
|
+
raise "Must specify output directory." unless args[1]
|
|
32
|
+
raise "Output directory already exists." if File.exists?(args[1])
|
|
33
|
+
|
|
34
|
+
input_dir = File.expand_path(args[0])
|
|
35
|
+
output_dir = File.expand_path(args[1])
|
|
36
|
+
|
|
37
|
+
index = Fixi::Index.new(input_dir)
|
|
38
|
+
Dir.mkdir(output_dir)
|
|
39
|
+
|
|
40
|
+
# if algorithms specified, must be a subset of those indexed
|
|
41
|
+
opts[:algorithms] ||= index.algorithms
|
|
42
|
+
set = Set.new(index.algorithms.split(","))
|
|
43
|
+
subset = Set.new(opts[:algorithms].split(","))
|
|
44
|
+
raise "Specified algorithm(s) must be a subset of #{index.algorithms}" unless subset.subset?(set)
|
|
45
|
+
|
|
46
|
+
manifiles = {}
|
|
47
|
+
|
|
48
|
+
begin
|
|
49
|
+
# write bag declaration
|
|
50
|
+
file = File.new(File.join(args[1], "bagit.txt"), "w")
|
|
51
|
+
file.puts("BagIt-Version: 0.97")
|
|
52
|
+
file.puts("Tag-File-Character-Encoding: UTF-8")
|
|
53
|
+
file.close
|
|
54
|
+
|
|
55
|
+
# open manifest files for writing
|
|
56
|
+
opts[:algorithms].split(",").each do |alg|
|
|
57
|
+
filename = File.join(args[1], "manifest-#{alg}.txt")
|
|
58
|
+
manifiles[alg] = File.new(filename, "w")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# copy all files, preserving attributes
|
|
62
|
+
index.each(input_dir) do |hash|
|
|
63
|
+
relpath = hash['relpath']
|
|
64
|
+
abspath = index.rootpath + '/' + relpath
|
|
65
|
+
if index.file_in_scope(relpath) && File.exists?(abspath)
|
|
66
|
+
bagrelpath = "data" + abspath[input_dir.length..-1]
|
|
67
|
+
destpath = args[1] + "/" + bagrelpath
|
|
68
|
+
manifiles.each do |alg, file|
|
|
69
|
+
file.puts("#{hash[alg]} #{bagrelpath}")
|
|
70
|
+
end
|
|
71
|
+
begin
|
|
72
|
+
FileUtils.cp(abspath, destpath, :preserve => true)
|
|
73
|
+
rescue
|
|
74
|
+
FileUtils.mkdir_p(File.dirname(destpath))
|
|
75
|
+
FileUtils.cp(abspath, destpath, :preserve => true)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
data_dir = output_dir + "/data"
|
|
81
|
+
|
|
82
|
+
# revisit all dirs under data/, copying orig dir metadata
|
|
83
|
+
Find.find(data_dir) do |dir|
|
|
84
|
+
if File.directory?(dir) && dir != data_dir
|
|
85
|
+
orig_dir = input_dir + dir[data_dir.length..-1]
|
|
86
|
+
Fixi::set_metadata(dir, File.stat(orig_dir))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
ensure
|
|
90
|
+
manifiles.each_value { |file| file.close }
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
data/lib/fixi/command/check.rb
CHANGED
|
@@ -5,9 +5,12 @@ class Fixi::Command::Check
|
|
|
5
5
|
"Verify the fixity of files in the index"
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
def self.arghelp
|
|
9
|
+
"[<dir>|<file>]"
|
|
10
|
+
end
|
|
11
|
+
|
|
8
12
|
def self.details
|
|
9
|
-
"
|
|
10
|
-
if specified.".pack
|
|
13
|
+
"If no argument is given, the current directory ('.') is assumed."
|
|
11
14
|
end
|
|
12
15
|
|
|
13
16
|
def execute args
|
|
@@ -15,6 +18,10 @@ class Fixi::Command::Check
|
|
|
15
18
|
banner Fixi::Command.banner "check"
|
|
16
19
|
opt :absolute, "Show absolute paths. By default, paths are reported
|
|
17
20
|
relative to the index root.".pack
|
|
21
|
+
opt :algorithms, "Checksum algorithm(s) to use if shallow isn't specified.
|
|
22
|
+
This is a comma-separated list, which may include md5, sha1, sha256, sha384,
|
|
23
|
+
sha512, and must be a subset of the indexed algorithms. If unspecified,
|
|
24
|
+
defaults to all indexed algorithms.".pack, :short => 'l', :type => :string
|
|
18
25
|
opt :shallow, "Do shallow comparisons when determining which files have
|
|
19
26
|
changed. If specified, only file sizes and mtimes will be used. By
|
|
20
27
|
default, checksums will also be computed and compared if necessary.".pack
|
|
@@ -24,6 +31,12 @@ class Fixi::Command::Check
|
|
|
24
31
|
path = File.expand_path(args[0] || ".")
|
|
25
32
|
index = Fixi::Index.new(path)
|
|
26
33
|
|
|
34
|
+
# if algorithms specified, must be a subset of those indexed
|
|
35
|
+
opts[:algorithms] ||= index.algorithms
|
|
36
|
+
set = Set.new(index.algorithms.split(","))
|
|
37
|
+
subset = Set.new(opts[:algorithms].split(","))
|
|
38
|
+
raise "Specified algorithm(s) must be a subset of #{index.algorithms}" unless subset.subset?(set)
|
|
39
|
+
|
|
27
40
|
index.each(args[0]) do |hash|
|
|
28
41
|
relpath = hash['relpath']
|
|
29
42
|
abspath = index.rootpath + '/' + relpath
|
|
@@ -38,9 +51,9 @@ class Fixi::Command::Check
|
|
|
38
51
|
detail = opts[:verbose] ? "mtime=#{Time.at(mtime).utc.iso8601} " : ""
|
|
39
52
|
puts "M #{detail}#{opts[:absolute] ? abspath : relpath}"
|
|
40
53
|
elsif not opts[:shallow]
|
|
41
|
-
hexdigests = Fixi::hexdigests(Fixi::digests(
|
|
54
|
+
hexdigests = Fixi::hexdigests(Fixi::digests(opts[:algorithms]), abspath)
|
|
42
55
|
i = 0
|
|
43
|
-
|
|
56
|
+
opts[:algorithms].split(',').each do |algorithm|
|
|
44
57
|
if hexdigests[i] != hash[algorithm]
|
|
45
58
|
detail = opts[:verbose] ? "#{algorithm}=#{hexdigests[i]} " : ""
|
|
46
59
|
puts "M #{detail}#{opts[:absolute] ? abspath : relpath}"
|
data/lib/fixi/command/commit.rb
CHANGED
|
@@ -7,9 +7,12 @@ class Fixi::Command::Commit
|
|
|
7
7
|
"Commit modified files to the index"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def self.arghelp
|
|
11
|
+
"[<dir>|<file>]"
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def self.details
|
|
11
|
-
"
|
|
12
|
-
if specified.".pack
|
|
15
|
+
"If no argument is given, the current directory ('.') is assumed."
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def execute args
|
data/lib/fixi/command/info.rb
CHANGED
|
@@ -6,9 +6,12 @@ class Fixi::Command::Info
|
|
|
6
6
|
"Display a summary of the index"
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def self.arghelp
|
|
10
|
+
"[<dir>]"
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
def self.details
|
|
10
|
-
"
|
|
11
|
-
if specified.".pack
|
|
14
|
+
"If no argument is given, the current directory ('.') is assumed."
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def execute args
|
data/lib/fixi/command/init.rb
CHANGED
data/lib/fixi/command/ls.rb
CHANGED
|
@@ -6,9 +6,12 @@ class Fixi::Command::Ls
|
|
|
6
6
|
"List contents of the index"
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def self.arghelp
|
|
10
|
+
"[<dir>|<file>]"
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
def self.details
|
|
10
|
-
"
|
|
11
|
-
if specified.".pack
|
|
14
|
+
"If no argument is given, the current directory ('.') is assumed."
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def execute args
|
data/lib/fixi/command/rm.rb
CHANGED
|
@@ -7,9 +7,12 @@ class Fixi::Command::Rm
|
|
|
7
7
|
"Delete old files from the index"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def self.arghelp
|
|
11
|
+
"[<dir>|<file>]"
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def self.details
|
|
11
|
-
"
|
|
12
|
-
if specified.".pack
|
|
15
|
+
"If no argument is given, the current directory ('.') is assumed."
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def execute args
|
data/lib/fixi/command/sum.rb
CHANGED
|
@@ -7,8 +7,12 @@ class Fixi::Command::Sum
|
|
|
7
7
|
"Calculate checksum(s) of a file"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def self.arghelp
|
|
11
|
+
"<file>"
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def self.details
|
|
11
|
-
|
|
15
|
+
"This command operates on files and does not require an index to exist."
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
def execute args
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'trollop'
|
|
2
|
+
require 'fixi/index'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
class Fixi::Command::Unbag
|
|
6
|
+
def self.synopsis
|
|
7
|
+
"Import files from a BagIt bag"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.arghelp
|
|
11
|
+
"<input-dir> <output-dir>"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.details
|
|
15
|
+
"Where:\n input-dir is the base directory of the bag.\n" +
|
|
16
|
+
" output-dir is the directory in which to import it."
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def execute args
|
|
20
|
+
opts = Trollop::options args do
|
|
21
|
+
banner Fixi::Command.banner "unbag"
|
|
22
|
+
opt :absolute, "Show absolute paths. By default, paths are reported
|
|
23
|
+
relative to the index root.".pack
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# validate args and bag dir
|
|
27
|
+
raise "Must specify input directory." unless args[0]
|
|
28
|
+
raise "Must specify output directory." unless args[1]
|
|
29
|
+
raise "Output directory already exists." if File.exists?(args[1])
|
|
30
|
+
|
|
31
|
+
input_dir = File.expand_path(args[0])
|
|
32
|
+
output_dir = File.expand_path(args[1])
|
|
33
|
+
|
|
34
|
+
index = Fixi::Index.new(File.dirname(output_dir))
|
|
35
|
+
Dir.mkdir(output_dir)
|
|
36
|
+
|
|
37
|
+
data_dir = input_dir + "/data"
|
|
38
|
+
raise "No data dir found in input dir." unless File.directory?(data_dir)
|
|
39
|
+
|
|
40
|
+
# build hash of manifest algorithm => file path
|
|
41
|
+
manifests = {}
|
|
42
|
+
indexed_algs = index.algorithms.split(",")
|
|
43
|
+
Dir.entries(input_dir).each do |child|
|
|
44
|
+
if child =~ /^manifest-.*\.txt/
|
|
45
|
+
alg = child[9..(child.length - 5)]
|
|
46
|
+
if (indexed_algs.include?(alg))
|
|
47
|
+
manifests[alg] = input_dir + "/" + child
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# copy all data to dest dir, subject to includes and excludes
|
|
53
|
+
Find.find(data_dir) do |abspath|
|
|
54
|
+
unless abspath == data_dir
|
|
55
|
+
relpath = abspath.slice(data_dir.length + 1..-1)
|
|
56
|
+
destpath = output_dir + "/" + relpath
|
|
57
|
+
if index.matches_any?(relpath, index.includes)
|
|
58
|
+
if index.matches_any?(relpath, index.excludes)
|
|
59
|
+
Find.prune
|
|
60
|
+
elsif not File.directory?(abspath)
|
|
61
|
+
begin
|
|
62
|
+
FileUtils.cp(abspath, destpath, :preserve => true)
|
|
63
|
+
rescue
|
|
64
|
+
FileUtils.mkdir_p(File.dirname(destpath))
|
|
65
|
+
FileUtils.cp(abspath, destpath, :preserve => true)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
else
|
|
69
|
+
Find.prune unless File.directory?(abspath)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# revisit all dirs under output_dir, copying orig dir metadata
|
|
75
|
+
Find.find(output_dir) do |dir|
|
|
76
|
+
if File.directory?(dir) && dir != output_dir
|
|
77
|
+
orig_dir = data_dir + dir[output_dir.length..-1]
|
|
78
|
+
Fixi::set_metadata(dir, File.stat(orig_dir))
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# add paths, sizes, and mtimes to db
|
|
83
|
+
index.find(output_dir) do |abspath|
|
|
84
|
+
relpath = index.relpath(abspath)
|
|
85
|
+
index.add(relpath, false)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# add manifest entries to db
|
|
89
|
+
manifests.each do |alg, manifest|
|
|
90
|
+
IO.foreach(manifest) do |line|
|
|
91
|
+
i = line.index(" ")
|
|
92
|
+
if i
|
|
93
|
+
digest = line[0..i-1].downcase
|
|
94
|
+
bagpath = line[i+6..-1].rstrip
|
|
95
|
+
relpath = index.relpath(output_dir + "/" + bagpath)
|
|
96
|
+
index.set_digest(relpath, alg, digest)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# for all new files, compute any required hashes and print A path/etc
|
|
102
|
+
algs = index.algorithms.split(",")
|
|
103
|
+
index.each(output_dir) do |hash|
|
|
104
|
+
relpath = hash['relpath']
|
|
105
|
+
abspath = index.rootpath + '/' + relpath
|
|
106
|
+
puts "A #{opts[:absolute] ? abspath : relpath}"
|
|
107
|
+
|
|
108
|
+
missing_digests = []
|
|
109
|
+
algs.each do |alg|
|
|
110
|
+
missing_digests << alg unless hash[alg]
|
|
111
|
+
end
|
|
112
|
+
if missing_digests.size > 0
|
|
113
|
+
digests = Fixi::digests(missing_digests.join(","))
|
|
114
|
+
hexdigests = Fixi::hexdigests(digests, abspath)
|
|
115
|
+
i = 0
|
|
116
|
+
missing_digests.each do |alg|
|
|
117
|
+
index.set_digest(relpath, alg, hexdigests[i])
|
|
118
|
+
i += 1
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
end
|
data/lib/fixi/command.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module Fixi::Command
|
|
2
2
|
def self.banner(name)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"#{const_get(
|
|
3
|
+
n = name.capitalize
|
|
4
|
+
"fixi-#{name}: #{const_get(n).synopsis}\n\n" +
|
|
5
|
+
"usage: fixi #{name} [<options>] #{const_get(n).arghelp}\n\n" +
|
|
6
|
+
"#{const_get(n).details}\n\n" +
|
|
6
7
|
"Options:"
|
|
7
8
|
end
|
|
8
9
|
end
|
data/lib/fixi/index.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'sqlite3'
|
|
2
2
|
|
|
3
3
|
class Fixi::Index
|
|
4
|
-
attr_reader :dotpath, :rootpath, :dbversion, :algorithms
|
|
4
|
+
attr_reader :dotpath, :rootpath, :dbversion, :algorithms, :includes, :excludes
|
|
5
5
|
|
|
6
6
|
def initialize(startpath, create=false, algorithms=nil)
|
|
7
7
|
startpath = File.expand_path(startpath || ".")
|
|
@@ -141,21 +141,27 @@ class Fixi::Index
|
|
|
141
141
|
@db.execute(sql, relpath)
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
-
def
|
|
144
|
+
def set_digest(relpath, alg, val)
|
|
145
|
+
sql = "update file set #{alg} = '#{val}' where relpath = ?"
|
|
146
|
+
@db.execute(sql, relpath)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def add(relpath, compute_checksums=true)
|
|
145
150
|
abspath = File.join(@rootpath, relpath)
|
|
146
|
-
sql = "insert into file (relpath, size, mtime
|
|
147
|
-
sql += @algorithms
|
|
148
|
-
sql += ") values (:relpath, :size, :mtime
|
|
151
|
+
sql = "insert into file (relpath, size, mtime"
|
|
152
|
+
sql += ", " + @algorithms if compute_checksums
|
|
153
|
+
sql += ") values (:relpath, :size, :mtime"
|
|
149
154
|
values = Hash.new
|
|
150
155
|
values[:relpath] = relpath
|
|
151
156
|
values[:size] = File.size abspath
|
|
152
157
|
values[:mtime] = File.mtime(abspath).to_i
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
if compute_checksums
|
|
159
|
+
hexdigests = Fixi::hexdigests(Fixi::digests(@algorithms), abspath)
|
|
160
|
+
i = 0
|
|
161
|
+
@algorithms.split(",").each do |alg|
|
|
162
|
+
sql += ", '" + hexdigests[i] + "'"
|
|
163
|
+
i += 1
|
|
164
|
+
end
|
|
159
165
|
end
|
|
160
166
|
sql += ")"
|
|
161
167
|
@db.execute(sql, values)
|
|
@@ -171,6 +177,13 @@ class Fixi::Index
|
|
|
171
177
|
puts "Fixi database version #{dbversion}"
|
|
172
178
|
end
|
|
173
179
|
|
|
180
|
+
def matches_any?(path, patterns)
|
|
181
|
+
patterns.each do |pattern|
|
|
182
|
+
return true if pattern.match(path)
|
|
183
|
+
end
|
|
184
|
+
return false
|
|
185
|
+
end
|
|
186
|
+
|
|
174
187
|
private
|
|
175
188
|
|
|
176
189
|
def load_patterns(name)
|
|
@@ -185,13 +198,6 @@ class Fixi::Index
|
|
|
185
198
|
result
|
|
186
199
|
end
|
|
187
200
|
|
|
188
|
-
def matches_any?(path, patterns)
|
|
189
|
-
patterns.each do |pattern|
|
|
190
|
-
return true if pattern.match(path)
|
|
191
|
-
end
|
|
192
|
-
return false
|
|
193
|
-
end
|
|
194
|
-
|
|
195
201
|
# Return the first .fixi directory we find while traversing up the tree
|
|
196
202
|
def find_dotpath(path, startpath=path)
|
|
197
203
|
dotpath = File.join(path, ".fixi")
|
data/lib/fixi/version.rb
CHANGED
data/lib/fixi.rb
CHANGED
|
@@ -39,4 +39,16 @@ module Fixi
|
|
|
39
39
|
}
|
|
40
40
|
hds
|
|
41
41
|
end
|
|
42
|
+
|
|
43
|
+
def self.set_metadata(path, stat)
|
|
44
|
+
File.utime(stat.atime, stat.mtime, path)
|
|
45
|
+
begin
|
|
46
|
+
File.chown(stat.uid, stat.gid, path)
|
|
47
|
+
rescue Errno::EPERM
|
|
48
|
+
File.chmod(stat.mode & 01777, path)
|
|
49
|
+
else
|
|
50
|
+
File.chmod(stat.mode, path)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
42
54
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Fixi::Command::Init do
|
|
4
|
+
describe "::synopsis" do
|
|
5
|
+
it 'should be a non-empty string' do
|
|
6
|
+
Fixi::Command::Init::synopsis.length.should_not == 0
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "::details" do
|
|
11
|
+
it 'should be a non-empty string' do
|
|
12
|
+
Fixi::Command::Init::details.length.should_not == 0
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "execute" do
|
|
17
|
+
include FixiTestHelperMethods
|
|
18
|
+
before do
|
|
19
|
+
@command = Fixi::Command::Init.new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should accept zero args" do
|
|
23
|
+
capture_stdout
|
|
24
|
+
@command.execute([])
|
|
25
|
+
release_stdout
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "String#pack" do
|
|
4
|
+
it 'should drop leading whitespace' do
|
|
5
|
+
"\n foo".pack.should == "foo"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'should drop trailing whitespace' do
|
|
9
|
+
"\n foo".pack.should == "foo"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'should turn multi whitespace into one space' do
|
|
13
|
+
"foo \n\n bar".pack.should == "foo bar"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
|
|
4
|
+
describe Fixi do
|
|
5
|
+
describe "::command" do
|
|
6
|
+
it 'should return nil for bogus name' do
|
|
7
|
+
Fixi::command("bogus").should == nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'should return instance for real name' do
|
|
11
|
+
Fixi::command("init").should_not == nil
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "::digests" do
|
|
16
|
+
it 'should raise error for bogus name' do
|
|
17
|
+
lambda { Fixi::digests("bogus") }.should raise_error
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'should return instance for real name' do
|
|
21
|
+
Fixi::digests("md5").should_not == nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "::hexdigests" do
|
|
26
|
+
before(:all) do
|
|
27
|
+
@file = Tempfile.new('foo')
|
|
28
|
+
@file.write('foo')
|
|
29
|
+
@file.close
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should compute correct single checksum' do
|
|
33
|
+
hexdigests = Fixi::hexdigests(Fixi::digests("md5"), @file.path)
|
|
34
|
+
hexdigests.should == ["acbd18db4cc2f85cedef654fccc4a4d8"]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'should compute correct multi checksum' do
|
|
38
|
+
hexdigests = Fixi::hexdigests(Fixi::digests("md5,sha1"), @file.path)
|
|
39
|
+
hexdigests.should == ["acbd18db4cc2f85cedef654fccc4a4d8",
|
|
40
|
+
"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
after(:all) do
|
|
44
|
+
@file.unlink
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'simplecov'
|
|
3
|
+
SimpleCov.start
|
|
4
|
+
require 'rspec'
|
|
5
|
+
require 'fixi'
|
|
6
|
+
|
|
7
|
+
require 'tempfile'
|
|
8
|
+
|
|
9
|
+
module FixiTestHelperMethods
|
|
10
|
+
# Start capturing stdout
|
|
11
|
+
def capture_stdout
|
|
12
|
+
@orig_stdout = $stdout
|
|
13
|
+
@stdout_file = Tempfile.new("stdout")
|
|
14
|
+
$stdout = @stdout_file
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Finish capturing stdout, setting @stdout to have each line of output
|
|
18
|
+
def release_stdout
|
|
19
|
+
$stdout = @orig_stdout
|
|
20
|
+
@stdout_file.rewind
|
|
21
|
+
@stdout = []
|
|
22
|
+
@stdout_file.each do |line|
|
|
23
|
+
@stdout << line
|
|
24
|
+
end
|
|
25
|
+
@stdout_file.unlink
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: fixi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.0
|
|
5
|
+
version: 0.1.0
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Chris Wilper
|
|
@@ -10,10 +10,10 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-12-
|
|
13
|
+
date: 2011-12-16 00:00:00 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
16
|
+
name: rspec
|
|
17
17
|
prerelease: false
|
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
19
19
|
none: false
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
- - ">="
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
23
|
version: "0"
|
|
24
|
-
type: :
|
|
24
|
+
type: :development
|
|
25
25
|
version_requirements: *id001
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: simplecov
|
|
28
28
|
prerelease: false
|
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
30
30
|
none: false
|
|
@@ -32,8 +32,30 @@ dependencies:
|
|
|
32
32
|
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
34
|
version: "0"
|
|
35
|
-
type: :
|
|
35
|
+
type: :development
|
|
36
36
|
version_requirements: *id002
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
name: trollop
|
|
39
|
+
prerelease: false
|
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
type: :runtime
|
|
47
|
+
version_requirements: *id003
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: sqlite3
|
|
50
|
+
prerelease: false
|
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
52
|
+
none: false
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: "0"
|
|
57
|
+
type: :runtime
|
|
58
|
+
version_requirements: *id004
|
|
37
59
|
description: Keeps an index of checksums and lets you update and verify them
|
|
38
60
|
email:
|
|
39
61
|
- cwilper@gmail.com
|
|
@@ -46,13 +68,15 @@ extra_rdoc_files: []
|
|
|
46
68
|
files:
|
|
47
69
|
- .gitignore
|
|
48
70
|
- Gemfile
|
|
49
|
-
-
|
|
71
|
+
- LICENSE
|
|
72
|
+
- README.md
|
|
50
73
|
- Rakefile
|
|
51
74
|
- bin/fixi
|
|
52
75
|
- fixi.gemspec
|
|
53
76
|
- lib/fixi.rb
|
|
54
77
|
- lib/fixi/command.rb
|
|
55
78
|
- lib/fixi/command/add.rb
|
|
79
|
+
- lib/fixi/command/bag.rb
|
|
56
80
|
- lib/fixi/command/check.rb
|
|
57
81
|
- lib/fixi/command/commit.rb
|
|
58
82
|
- lib/fixi/command/info.rb
|
|
@@ -60,9 +84,14 @@ files:
|
|
|
60
84
|
- lib/fixi/command/ls.rb
|
|
61
85
|
- lib/fixi/command/rm.rb
|
|
62
86
|
- lib/fixi/command/sum.rb
|
|
87
|
+
- lib/fixi/command/unbag.rb
|
|
63
88
|
- lib/fixi/index.rb
|
|
64
89
|
- lib/fixi/patch/string_pack.rb
|
|
65
90
|
- lib/fixi/version.rb
|
|
91
|
+
- spec/lib/fixi/command/init_spec.rb
|
|
92
|
+
- spec/lib/fixi/patch/string_pack_spec.rb
|
|
93
|
+
- spec/lib/fixi_spec.rb
|
|
94
|
+
- spec/spec_helper.rb
|
|
66
95
|
homepage: ""
|
|
67
96
|
licenses: []
|
|
68
97
|
|
|
@@ -90,5 +119,8 @@ rubygems_version: 1.8.11
|
|
|
90
119
|
signing_key:
|
|
91
120
|
specification_version: 3
|
|
92
121
|
summary: A fixity tracker utility
|
|
93
|
-
test_files:
|
|
94
|
-
|
|
122
|
+
test_files:
|
|
123
|
+
- spec/lib/fixi/command/init_spec.rb
|
|
124
|
+
- spec/lib/fixi/patch/string_pack_spec.rb
|
|
125
|
+
- spec/lib/fixi_spec.rb
|
|
126
|
+
- spec/spec_helper.rb
|
data/README
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Fixi - Source Code
|
|
2
|
-
==================
|
|
3
|
-
|
|
4
|
-
A fixity tracker utility.
|
|
5
|
-
|
|
6
|
-
Installing From RubyGems.org
|
|
7
|
-
----------------------------
|
|
8
|
-
|
|
9
|
-
> [sudo] gem install fixi
|
|
10
|
-
|
|
11
|
-
Installing From Source
|
|
12
|
-
----------------------
|
|
13
|
-
|
|
14
|
-
> [sudo] rake install
|
|
15
|
-
|
|
16
|
-
Usage
|
|
17
|
-
-----
|
|
18
|
-
|
|
19
|
-
To see usage, after installing, run fixi --help
|