fxn-unmac 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README +6 -5
- data/bin/unmac +4 -0
- data/lib/unmacer.rb +12 -5
- data/test/test_unmac.rb +28 -1
- data/test/test_unmacer.rb +17 -0
- data/unmac.gemspec +2 -2
- metadata +1 -1
data/MIT-LICENSE
CHANGED
data/README
CHANGED
@@ -6,6 +6,7 @@ Usage:
|
|
6
6
|
Options:
|
7
7
|
-h, --help Print this help
|
8
8
|
-v, --verbose Show processing
|
9
|
+
-p, --pretend Show what would be deleted, but don't do it
|
9
10
|
-s, --keep-spotlight Do not delete Spotlight data
|
10
11
|
-f, --keep-fsevents Do not delete Time Machine stuff
|
11
12
|
-t, --keep-trashes Do not delete volume trashes
|
@@ -29,7 +30,7 @@ Description:
|
|
29
30
|
What's deleted:
|
30
31
|
This is just a summary, for more detailed explanations and pointers see the
|
31
32
|
comments in unmacer.rb:
|
32
|
-
|
33
|
+
|
33
34
|
* Spotlight leaves a folder called ".Spotlight-V100" in the root directory
|
34
35
|
of volumes.
|
35
36
|
|
@@ -43,21 +44,21 @@ What's deleted:
|
|
43
44
|
|
44
45
|
* Finder and Spotlight data related to each folder gets stored in an
|
45
46
|
extra file called ".DS_Store".
|
46
|
-
|
47
|
+
|
47
48
|
* For each file "foo.txt", its resource fork and some additional stuff
|
48
49
|
are stored in an accompaining ghost file called "._foo.txt". The pattern
|
49
50
|
is to prepend "._" to the original file name.
|
50
|
-
|
51
|
+
|
51
52
|
Some stuff is only found in the root folder of volumes, unmac looks for them
|
52
53
|
in any directory you pass as argument, but not on their subdirectories.
|
53
54
|
|
54
55
|
Installation:
|
55
56
|
unmac is distributed as a Ruby gem. Once you have Ruby and RubyGems installed
|
56
57
|
execute
|
57
|
-
|
58
|
+
|
58
59
|
gem sources -a http://gems.github.com # you need this only once
|
59
60
|
gem install fxn-unmac
|
60
|
-
|
61
|
+
|
61
62
|
This program is portable.
|
62
63
|
|
63
64
|
License:
|
data/bin/unmac
CHANGED
@@ -14,6 +14,7 @@ Usage:
|
|
14
14
|
Options:
|
15
15
|
-h, --help Print this help
|
16
16
|
-v, --verbose Show processing
|
17
|
+
-p, --pretend Show what would be deleted, but don't do it
|
17
18
|
-s, --keep-spotlight Do not delete Spotlight data
|
18
19
|
-f, --keep-fsevents Do not delete Time Machine stuff
|
19
20
|
-t, --keep-trashes Do not delete volume trashes
|
@@ -64,6 +65,7 @@ end
|
|
64
65
|
opts = GetoptLong.new(
|
65
66
|
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
66
67
|
['--verbose', '-v', GetoptLong::NO_ARGUMENT],
|
68
|
+
['--pretend', '-p', GetoptLong::NO_ARGUMENT],
|
67
69
|
['--keep-spotlight', '-s', GetoptLong::NO_ARGUMENT],
|
68
70
|
['--keep-fsevents', '-f', GetoptLong::NO_ARGUMENT],
|
69
71
|
['--keep-trashes', '-t', GetoptLong::NO_ARGUMENT],
|
@@ -83,6 +85,8 @@ begin
|
|
83
85
|
usage and exit
|
84
86
|
when '--verbose'
|
85
87
|
unmacer.verbose = true
|
88
|
+
when '--pretend'
|
89
|
+
unmacer.pretend = true
|
86
90
|
when /\A--(keep-.*)/
|
87
91
|
flag = $1.gsub('-', '_')
|
88
92
|
unmacer.send("#{flag}=", true)
|
data/lib/unmacer.rb
CHANGED
@@ -3,6 +3,7 @@ require 'find'
|
|
3
3
|
|
4
4
|
class Unmacer
|
5
5
|
attr_accessor :verbose,
|
6
|
+
:pretend,
|
6
7
|
:keep_spotlight,
|
7
8
|
:keep_fsevents,
|
8
9
|
:keep_trashes,
|
@@ -19,6 +20,7 @@ class Unmacer
|
|
19
20
|
|
20
21
|
def initialize
|
21
22
|
self.verbose = false
|
23
|
+
self.pretend = false
|
22
24
|
self.keep_spotlight = false
|
23
25
|
self.keep_fsevents = false
|
24
26
|
self.keep_trashes = false
|
@@ -67,11 +69,16 @@ private
|
|
67
69
|
|
68
70
|
def delete(parent, file_or_directory)
|
69
71
|
name = File.join(parent, file_or_directory)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
if File.exists?(name)
|
73
|
+
if pretend
|
74
|
+
puts "would delete #{name}"
|
75
|
+
else
|
76
|
+
FileUtils.rm_r(name)
|
77
|
+
puts "deleted #{name}" if verbose
|
78
|
+
end
|
79
|
+
end
|
80
|
+
rescue Exception => e
|
81
|
+
$stderr.puts("could not delete #{name}: #{e.message}")
|
75
82
|
end
|
76
83
|
|
77
84
|
# Spotlight saves all its index-related files in the .Spotlight-V100 directory
|
data/test/test_unmac.rb
CHANGED
@@ -17,6 +17,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
17
17
|
def test_no_options
|
18
18
|
unmacer = call_unmac('dummy')
|
19
19
|
assert !unmacer.verbose
|
20
|
+
assert !unmacer.pretend
|
20
21
|
assert !unmacer.keep_spotlight
|
21
22
|
assert !unmacer.keep_fsevents
|
22
23
|
assert !unmacer.keep_trashes
|
@@ -31,6 +32,23 @@ class TestUnmac < Test::Unit::TestCase
|
|
31
32
|
for opt in ['--verbose', '-v']
|
32
33
|
unmacer = call_unmac(opt, 'dummy')
|
33
34
|
assert unmacer.verbose
|
35
|
+
assert !unmacer.pretend
|
36
|
+
assert !unmacer.keep_spotlight
|
37
|
+
assert !unmacer.keep_fsevents
|
38
|
+
assert !unmacer.keep_trashes
|
39
|
+
assert !unmacer.keep_macosx
|
40
|
+
assert !unmacer.keep_dsstore
|
41
|
+
assert !unmacer.keep_apple_double
|
42
|
+
assert !unmacer.keep_apple_double_orphans
|
43
|
+
assert_equal %w(dummy), ARGV
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_pretend
|
48
|
+
for opt in ['--pretend', '-p']
|
49
|
+
unmacer = call_unmac(opt, 'dummy')
|
50
|
+
assert !unmacer.verbose
|
51
|
+
assert unmacer.pretend
|
34
52
|
assert !unmacer.keep_spotlight
|
35
53
|
assert !unmacer.keep_fsevents
|
36
54
|
assert !unmacer.keep_trashes
|
@@ -46,6 +64,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
46
64
|
for opt in ['--keep-spotlight', '-s']
|
47
65
|
unmacer = call_unmac(opt, 'dummy')
|
48
66
|
assert !unmacer.verbose
|
67
|
+
assert !unmacer.pretend
|
49
68
|
assert unmacer.keep_spotlight
|
50
69
|
assert !unmacer.keep_fsevents
|
51
70
|
assert !unmacer.keep_trashes
|
@@ -61,6 +80,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
61
80
|
for opt in ['--keep-fsevents', '-f']
|
62
81
|
unmacer = call_unmac(opt, 'dummy')
|
63
82
|
assert !unmacer.verbose
|
83
|
+
assert !unmacer.pretend
|
64
84
|
assert !unmacer.keep_spotlight
|
65
85
|
assert unmacer.keep_fsevents
|
66
86
|
assert !unmacer.keep_trashes
|
@@ -76,6 +96,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
76
96
|
for opt in ['--keep-trashes', '-t']
|
77
97
|
unmacer = call_unmac(opt, 'dummy')
|
78
98
|
assert !unmacer.verbose
|
99
|
+
assert !unmacer.pretend
|
79
100
|
assert !unmacer.keep_spotlight
|
80
101
|
assert !unmacer.keep_fsevents
|
81
102
|
assert unmacer.keep_trashes
|
@@ -91,6 +112,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
91
112
|
for opt in ['--keep-macosx', '-m']
|
92
113
|
unmacer = call_unmac(opt, 'dummy')
|
93
114
|
assert !unmacer.verbose
|
115
|
+
assert !unmacer.pretend
|
94
116
|
assert !unmacer.keep_spotlight
|
95
117
|
assert !unmacer.keep_fsevents
|
96
118
|
assert !unmacer.keep_trashes
|
@@ -106,6 +128,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
106
128
|
for opt in ['--keep-dsstore', '-r']
|
107
129
|
unmacer = call_unmac(opt, 'dummy')
|
108
130
|
assert !unmacer.verbose
|
131
|
+
assert !unmacer.pretend
|
109
132
|
assert !unmacer.keep_spotlight
|
110
133
|
assert !unmacer.keep_fsevents
|
111
134
|
assert !unmacer.keep_trashes
|
@@ -121,6 +144,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
121
144
|
for opt in ['--keep-apple-double', '-d']
|
122
145
|
unmacer = call_unmac(opt, 'dummy')
|
123
146
|
assert !unmacer.verbose
|
147
|
+
assert !unmacer.pretend
|
124
148
|
assert !unmacer.keep_spotlight
|
125
149
|
assert !unmacer.keep_fsevents
|
126
150
|
assert !unmacer.keep_trashes
|
@@ -136,6 +160,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
136
160
|
for opt in ['--keep-apple-double-orphans', '-o']
|
137
161
|
unmacer = call_unmac(opt, 'dummy')
|
138
162
|
assert !unmacer.verbose
|
163
|
+
assert !unmacer.pretend
|
139
164
|
assert !unmacer.keep_spotlight
|
140
165
|
assert !unmacer.keep_fsevents
|
141
166
|
assert !unmacer.keep_trashes
|
@@ -150,6 +175,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
150
175
|
def test_mix_1
|
151
176
|
unmacer = call_unmac(*%w(-v -f -m -d dummy))
|
152
177
|
assert unmacer.verbose
|
178
|
+
assert !unmacer.pretend
|
153
179
|
assert !unmacer.keep_spotlight
|
154
180
|
assert unmacer.keep_fsevents
|
155
181
|
assert !unmacer.keep_trashes
|
@@ -163,6 +189,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
163
189
|
def test_mix_2
|
164
190
|
unmacer = call_unmac(*%w(-s -t -r -o dummy))
|
165
191
|
assert !unmacer.verbose
|
192
|
+
assert !unmacer.pretend
|
166
193
|
assert unmacer.keep_spotlight
|
167
194
|
assert !unmacer.keep_fsevents
|
168
195
|
assert unmacer.keep_trashes
|
@@ -174,7 +201,7 @@ class TestUnmac < Test::Unit::TestCase
|
|
174
201
|
end
|
175
202
|
|
176
203
|
def test_help
|
177
|
-
buf =
|
204
|
+
buf = ''
|
178
205
|
$> = StringIO.open(buf, 'w')
|
179
206
|
call_unmac('-h')
|
180
207
|
$> = $stdout
|
data/test/test_unmacer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
|
3
|
+
require 'stringio'
|
3
4
|
require 'fileutils'
|
4
5
|
require 'set'
|
5
6
|
require 'unmacer'
|
@@ -54,6 +55,22 @@ class TestUnmacer < Test::Unit::TestCase
|
|
54
55
|
assert read_struct.empty?
|
55
56
|
end
|
56
57
|
|
58
|
+
def test_pretend
|
59
|
+
dirs = [Unmacer::SPOTLIGHT, Unmacer::FSEVENTS, Unmacer::TRASHES, Unmacer::MACOSX]
|
60
|
+
create_struct(dirs, '._dummy')
|
61
|
+
buf = ''
|
62
|
+
$> = StringIO.new(buf, 'w')
|
63
|
+
@unmacer.pretend = true
|
64
|
+
unmac!
|
65
|
+
$> = $stdout
|
66
|
+
assert Set.new(dirs + ['._dummy']), Set.new(read_struct)
|
67
|
+
assert_match /^would delete.*\.Spotlight/, buf
|
68
|
+
assert_match /^would delete.*\.fsevents/, buf
|
69
|
+
assert_match /^would delete.*\.Trashes/, buf
|
70
|
+
assert_match /^would delete.*__MACOSX/, buf
|
71
|
+
assert_match /^would delete.*\._dummy/, buf
|
72
|
+
end
|
73
|
+
|
57
74
|
def test_spotlight
|
58
75
|
create_struct(Unmacer::SPOTLIGHT)
|
59
76
|
unmac!
|
data/unmac.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'unmac'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '0.3'
|
4
4
|
spec.summary = 'Delete spurious Mac files under a directory or volume'
|
5
5
|
spec.homepage = 'http://github.com/fxn/unmac/tree/master'
|
6
6
|
spec.executables = %w(unmac)
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.test_files = %w(
|
12
12
|
test/test_unmacer.rb
|
13
|
-
test/test_unmac.rb
|
13
|
+
test/test_unmac.rb
|
14
14
|
)
|
15
15
|
|
16
16
|
spec.files = %w(
|