clutil 2010.129.0 → 2010.132.1
Sign up to get free protection for your applications and to get access to all the features.
- data/cl/util/file.rb +97 -5
- data/cl/util/install.rb +1 -1
- data/cl/util/net.rb +20 -0
- data/cl/util/string.rb +2 -2
- data/cl/util/test/dirsizetest.rb +11 -12
- data/cl/util/test/filetest.rb +116 -50
- data/cl/util/test/nettest.rb +13 -0
- data/cl/util/test/stringtest.rb +4 -4
- data/cl/util/test.rb +21 -20
- data/cl/util/util.rb +2 -2
- data/cl/util/win.rb +2 -3
- metadata +5 -4
data/cl/util/file.rb
CHANGED
@@ -62,8 +62,7 @@ this Software without prior written authorization of the copyright holder.
|
|
62
62
|
(X11 license)
|
63
63
|
=end
|
64
64
|
|
65
|
-
require '
|
66
|
-
#require 'cl/util/win'
|
65
|
+
require 'fileutils'
|
67
66
|
|
68
67
|
class Dir
|
69
68
|
def Dir.empty?(dirname)
|
@@ -82,7 +81,7 @@ end
|
|
82
81
|
|
83
82
|
class << File
|
84
83
|
def extension(filename)
|
85
|
-
res = filename.scan(/\.[^.]*$/).to_s
|
84
|
+
res = filename.scan(/\.[^.]*$/)[0].to_s
|
86
85
|
res.gsub!(/\./, '')
|
87
86
|
res = nil if res.empty?
|
88
87
|
res
|
@@ -96,8 +95,11 @@ class << File
|
|
96
95
|
File.delete(file)
|
97
96
|
end
|
98
97
|
end
|
99
|
-
|
98
|
+
|
99
|
+
# returns false if up-to-date check passed and the file was not copied.
|
100
|
+
# returns true if up-to-date check failed and the file was copied.
|
100
101
|
def backup(src, dst, bincompare=false)
|
102
|
+
installed = false
|
101
103
|
if (
|
102
104
|
File.exists?(dst) &&
|
103
105
|
(
|
@@ -105,7 +107,8 @@ class << File
|
|
105
107
|
(File.stat(src).size != File.stat(dst).size)
|
106
108
|
)
|
107
109
|
) || !File.exists?(dst) || bincompare
|
108
|
-
|
110
|
+
FileUtils.install src, dst, :verbose => true
|
111
|
+
installed = true
|
109
112
|
end
|
110
113
|
|
111
114
|
if !File.stat(dst).writable?
|
@@ -117,6 +120,7 @@ class << File
|
|
117
120
|
new_atime = Time.now
|
118
121
|
File.utime(new_atime, File.stat(src).mtime, dst)
|
119
122
|
File.chmod(0444, dst) if set_ro
|
123
|
+
return installed
|
120
124
|
end
|
121
125
|
|
122
126
|
# human readable size
|
@@ -208,3 +212,91 @@ module ClUtilFile
|
|
208
212
|
end
|
209
213
|
=end
|
210
214
|
end
|
215
|
+
|
216
|
+
|
217
|
+
class Dir
|
218
|
+
# Dir.mktmpdir creates a temporary directory.
|
219
|
+
#
|
220
|
+
# [Copied from Ruby 1.9]
|
221
|
+
#
|
222
|
+
# The directory is created with 0700 permission.
|
223
|
+
#
|
224
|
+
# The prefix and suffix of the name of the directory is specified by
|
225
|
+
# the optional first argument, <i>prefix_suffix</i>.
|
226
|
+
# - If it is not specified or nil, "d" is used as the prefix and no suffix is used.
|
227
|
+
# - If it is a string, it is used as the prefix and no suffix is used.
|
228
|
+
# - If it is an array, first element is used as the prefix and second element is used as a suffix.
|
229
|
+
#
|
230
|
+
# Dir.mktmpdir {|dir| dir is ".../d..." }
|
231
|
+
# Dir.mktmpdir("foo") {|dir| dir is ".../foo..." }
|
232
|
+
# Dir.mktmpdir(["foo", "bar"]) {|dir| dir is ".../foo...bar" }
|
233
|
+
#
|
234
|
+
# The directory is created under Dir.tmpdir or
|
235
|
+
# the optional second argument <i>tmpdir</i> if non-nil value is given.
|
236
|
+
#
|
237
|
+
# Dir.mktmpdir {|dir| dir is "#{Dir.tmpdir}/d..." }
|
238
|
+
# Dir.mktmpdir(nil, "/var/tmp") {|dir| dir is "/var/tmp/d..." }
|
239
|
+
#
|
240
|
+
# If a block is given,
|
241
|
+
# it is yielded with the path of the directory.
|
242
|
+
# The directory and its contents are removed
|
243
|
+
# using FileUtils.remove_entry_secure before Dir.mktmpdir returns.
|
244
|
+
# The value of the block is returned.
|
245
|
+
#
|
246
|
+
# Dir.mktmpdir {|dir|
|
247
|
+
# # use the directory...
|
248
|
+
# open("#{dir}/foo", "w") { ... }
|
249
|
+
# }
|
250
|
+
#
|
251
|
+
# If a block is not given,
|
252
|
+
# The path of the directory is returned.
|
253
|
+
# In this case, Dir.mktmpdir doesn't remove the directory.
|
254
|
+
#
|
255
|
+
# dir = Dir.mktmpdir
|
256
|
+
# begin
|
257
|
+
# # use the directory...
|
258
|
+
# open("#{dir}/foo", "w") { ... }
|
259
|
+
# ensure
|
260
|
+
# # remove the directory.
|
261
|
+
# FileUtils.remove_entry_secure dir
|
262
|
+
# end
|
263
|
+
#
|
264
|
+
def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil)
|
265
|
+
case prefix_suffix
|
266
|
+
when nil
|
267
|
+
prefix = "d"
|
268
|
+
suffix = ""
|
269
|
+
when String
|
270
|
+
prefix = prefix_suffix
|
271
|
+
suffix = ""
|
272
|
+
when Array
|
273
|
+
prefix = prefix_suffix[0]
|
274
|
+
suffix = prefix_suffix[1]
|
275
|
+
else
|
276
|
+
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
277
|
+
end
|
278
|
+
tmpdir ||= Dir.tmpdir
|
279
|
+
t = Time.now.strftime("%Y%m%d")
|
280
|
+
n = nil
|
281
|
+
begin
|
282
|
+
path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
283
|
+
path << "-#{n}" if n
|
284
|
+
path << suffix
|
285
|
+
Dir.mkdir(path, 0700)
|
286
|
+
rescue Errno::EEXIST
|
287
|
+
n ||= 0
|
288
|
+
n += 1
|
289
|
+
retry
|
290
|
+
end
|
291
|
+
|
292
|
+
if block_given?
|
293
|
+
begin
|
294
|
+
yield path
|
295
|
+
ensure
|
296
|
+
FileUtils.remove_entry_secure path
|
297
|
+
end
|
298
|
+
else
|
299
|
+
path
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
data/cl/util/install.rb
CHANGED
data/cl/util/net.rb
CHANGED
@@ -4,6 +4,26 @@ module ClUtilNet
|
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
|
+
class NetUse
|
8
|
+
def initialize(unc, user='', password='')
|
9
|
+
@unc = unc
|
10
|
+
@user = user
|
11
|
+
@password = password
|
12
|
+
end
|
13
|
+
|
14
|
+
def attached?
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def attach(drive='')
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def detach
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
7
27
|
if __FILE__ == $0
|
8
28
|
include ClUtilNet
|
9
29
|
|
data/cl/util/string.rb
CHANGED
@@ -35,7 +35,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
35
35
|
|
36
36
|
class String
|
37
37
|
def get_indent
|
38
|
-
scan(/^(\s*)/).to_s
|
38
|
+
scan(/^(\s*)/).flatten[0].to_s
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -61,5 +61,5 @@ end
|
|
61
61
|
def here_ltrim(s, add_indent_amt=0)
|
62
62
|
a = s.split("\n", -1)
|
63
63
|
trim_indent_amt = a[0].get_indent.length
|
64
|
-
|
64
|
+
indent(s, add_indent_amt - trim_indent_amt)
|
65
65
|
end
|
data/cl/util/test/dirsizetest.rb
CHANGED
@@ -30,9 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
30
|
--------------------------------------------------------------------------------
|
31
31
|
=end
|
32
32
|
|
33
|
-
|
34
|
-
require '
|
35
|
-
require 'dirsize'
|
33
|
+
require File.dirname(__FILE__) + '/../test'
|
34
|
+
require File.dirname(__FILE__) + '/../dirsize'
|
36
35
|
require 'test/unit'
|
37
36
|
|
38
37
|
TestData = Struct.new("TestData",
|
@@ -54,7 +53,7 @@ class TestDirSize < TempDirTest
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def test_larger_singleton
|
57
|
-
|
56
|
+
make_sample_text_file('', 5000)
|
58
57
|
@test_data.clusterSize = 4096
|
59
58
|
@test_data.expectedFileSize = 5000
|
60
59
|
@test_data.expectedDiskSpace = (4096 * 2)
|
@@ -69,7 +68,7 @@ class TestDirSize < TempDirTest
|
|
69
68
|
|
70
69
|
def do_test_dir_size(test_data)
|
71
70
|
dir_size = DirSize.new
|
72
|
-
dir_size.directory = @
|
71
|
+
dir_size.directory = @temp_dir
|
73
72
|
dir_size.clusterSize = test_data.clusterSize
|
74
73
|
dir_size.getSize
|
75
74
|
assert_equal(test_data.expectedFileSize, dir_size.fileSize(false))
|
@@ -91,7 +90,7 @@ class TestDirSize < TempDirTest
|
|
91
90
|
end
|
92
91
|
|
93
92
|
def test_small_singleton
|
94
|
-
|
93
|
+
make_sample_text_file('', 1000)
|
95
94
|
@test_data.clusterSize = 4096
|
96
95
|
@test_data.expectedFileSize = 1000
|
97
96
|
@test_data.expectedDiskSpace = (4096 * 1)
|
@@ -105,12 +104,12 @@ class TestDirSize < TempDirTest
|
|
105
104
|
end
|
106
105
|
|
107
106
|
def test_sub_dir
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
107
|
+
make_sub_dir('suba')
|
108
|
+
make_sub_dir("suba\\suba1")
|
109
|
+
make_sample_text_file('', 1000)
|
110
|
+
make_sample_text_file('suba', 1000)
|
111
|
+
make_sample_text_file("suba\\suba1", 1000)
|
112
|
+
make_sample_text_file("suba\\suba1", 2000)
|
114
113
|
@test_data.clusterSize = 4096
|
115
114
|
@test_data.expectedFileSize = 1000
|
116
115
|
@test_data.expectedDiskSpace = (4096 * 1)
|
data/cl/util/test/filetest.rb
CHANGED
@@ -32,23 +32,22 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
32
|
(based on BSD Open Source License)
|
33
33
|
=end
|
34
34
|
|
35
|
-
|
36
|
-
require '
|
35
|
+
require File.dirname(__FILE__) + '/../file'
|
36
|
+
require File.dirname(__FILE__) + '/../test'
|
37
37
|
require 'test/unit'
|
38
|
-
require 'ftools'
|
39
38
|
|
40
39
|
# don't inherit from clutiltest.rb.TempDirTest, it uses things that are tested here
|
41
40
|
class TestUtilFile < Test::Unit::TestCase
|
42
41
|
READ_WRITE = 0644
|
43
42
|
READ_ONLY = 0444
|
44
43
|
|
45
|
-
def
|
46
|
-
f = File.new(
|
44
|
+
def create_test_file(file_name, content, mtime=Time.now, attr=READ_WRITE)
|
45
|
+
f = File.new(file_name, 'w+')
|
47
46
|
f.puts(content)
|
48
47
|
f.flush
|
49
48
|
f.close
|
50
|
-
File.utime(mtime, mtime,
|
51
|
-
File.chmod(attr,
|
49
|
+
File.utime(mtime, mtime, file_name)
|
50
|
+
File.chmod(attr, file_name)
|
52
51
|
end
|
53
52
|
|
54
53
|
def setup
|
@@ -60,7 +59,7 @@ class TestUtilFile < Test::Unit::TestCase
|
|
60
59
|
@dirs.reverse_each { | dirname | Dir.delete(dirname) if File.exists?(dirname) } if @dirs
|
61
60
|
end
|
62
61
|
|
63
|
-
def
|
62
|
+
def do_test_del_tree(attr)
|
64
63
|
@dirs = ['/tmp/utilfiletest',
|
65
64
|
'/tmp/utilfiletest/subA',
|
66
65
|
'/tmp/utilfiletest/subA/subA1',
|
@@ -68,84 +67,84 @@ class TestUtilFile < Test::Unit::TestCase
|
|
68
67
|
'/tmp/utilfiletest/subB',
|
69
68
|
'/tmp/utilfiletest/subB/subB1',
|
70
69
|
'/tmp/utilfiletest/subB/subB1/subB1a']
|
71
|
-
@dirs.each { |
|
70
|
+
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
72
71
|
@files = ['/tmp/utilfiletest/subA/blah.txt',
|
73
72
|
'/tmp/utilfiletest/subA/subA1/blah.txt',
|
74
73
|
'/tmp/utilfiletest/subA/subA2/blah.txt',
|
75
74
|
'/tmp/utilfiletest/subB/blah.txt',
|
76
75
|
'/tmp/utilfiletest/subB/subB1/blah.txt',
|
77
76
|
'/tmp/utilfiletest/subB/subB1/subB1a/blah.txt']
|
78
|
-
@files.each { | filename |
|
77
|
+
@files.each { | filename | create_test_file(filename, 'test content', Time.now, attr) }
|
79
78
|
ClUtilFile.delTree(@dirs[0])
|
80
|
-
@files.each { |
|
81
|
-
@dirs.each { |
|
79
|
+
@files.each { | file_name | assert(!File.exists?(file_name)) }
|
80
|
+
@dirs.each { | dir_name | assert(!File.exists?(dir_name)) }
|
82
81
|
end
|
83
82
|
|
84
|
-
def
|
85
|
-
|
83
|
+
def test_del_tree
|
84
|
+
do_test_del_tree(READ_WRITE)
|
86
85
|
end
|
87
86
|
|
88
|
-
def
|
89
|
-
|
87
|
+
def test_del_tree_ro_files
|
88
|
+
do_test_del_tree(READ_ONLY)
|
90
89
|
end
|
91
90
|
|
92
|
-
def
|
91
|
+
def test_del_tree_file_name_match
|
93
92
|
@dirs = ['/tmp/utilfiletest',
|
94
93
|
'/tmp/utilfiletest/subA',
|
95
94
|
'/tmp/utilfiletest/subB']
|
96
|
-
@dirs.each { |
|
97
|
-
@
|
95
|
+
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
96
|
+
@files_to_stay = ['/tmp/utilfiletest/subA/blah.doc',
|
98
97
|
'/tmp/utilfiletest/subB/blah.doc']
|
99
|
-
@
|
98
|
+
@files_to_delete = ['/tmp/utilfiletest/subA/blah.txt',
|
100
99
|
'/tmp/utilfiletest/subB/blah.txt']
|
101
|
-
@files << @
|
102
|
-
@files << @
|
100
|
+
@files << @files_to_stay
|
101
|
+
@files << @files_to_delete
|
103
102
|
@files.flatten!
|
104
103
|
|
105
|
-
@
|
106
|
-
@
|
104
|
+
@files_to_stay.each { | filename | create_test_file(filename, 'test content') }
|
105
|
+
@files_to_delete.each { | filename | create_test_file(filename, 'test content') }
|
107
106
|
ClUtilFile.delTree(@dirs[0], '*.txt')
|
108
|
-
@
|
109
|
-
@
|
107
|
+
@files_to_stay.each { | file_name | assert(File.exists?(file_name)) }
|
108
|
+
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
110
109
|
ClUtilFile.delTree(@dirs[0])
|
111
|
-
@
|
112
|
-
@
|
113
|
-
@dirs.each { |
|
110
|
+
@files_to_stay.each { | file_name | assert(!File.exists?(file_name)) }
|
111
|
+
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
112
|
+
@dirs.each { | dir_name | assert(!File.exists?(dir_name)) }
|
114
113
|
end
|
115
114
|
|
116
|
-
def
|
115
|
+
def test_del_tree_aging
|
117
116
|
@dirs = ['/tmp/utilfiletest',
|
118
117
|
'/tmp/utilfiletest/subA',
|
119
118
|
'/tmp/utilfiletest/subB']
|
120
|
-
@dirs.each { |
|
121
|
-
@
|
119
|
+
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
120
|
+
@files_to_stay = ['/tmp/utilfiletest/subA/blah0.txt',
|
122
121
|
'/tmp/utilfiletest/subB/blah1.txt']
|
123
|
-
@
|
122
|
+
@files_to_delete = ['/tmp/utilfiletest/subA/blah2.txt',
|
124
123
|
'/tmp/utilfiletest/subB/blah3.txt']
|
125
|
-
@files << @
|
126
|
-
@files << @
|
124
|
+
@files << @files_to_stay
|
125
|
+
@files << @files_to_delete
|
127
126
|
@files.flatten!
|
128
127
|
|
129
|
-
@
|
128
|
+
@files_to_stay.each { | filename | create_test_file(filename, 'test content') }
|
130
129
|
|
131
130
|
day = 60 * 60 * 24
|
132
|
-
|
133
|
-
|
134
|
-
@
|
131
|
+
eight_days = day * 8
|
132
|
+
seven_days = day * 7
|
133
|
+
@files_to_delete.each { | filename | create_test_file(filename, 'test content', Time.now - eight_days) }
|
135
134
|
|
136
|
-
ClUtilFile.delTree(@dirs[0]) { |
|
137
|
-
(File.mtime(
|
135
|
+
ClUtilFile.delTree(@dirs[0]) { | file_name |
|
136
|
+
(File.mtime(file_name) < (Time.now - seven_days))
|
138
137
|
}
|
139
138
|
|
140
|
-
@
|
141
|
-
@
|
139
|
+
@files_to_stay.each { | file_name | assert(File.exists?(file_name)) }
|
140
|
+
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
142
141
|
ClUtilFile.delTree(@dirs[0])
|
143
|
-
@
|
144
|
-
@
|
145
|
-
@dirs.each { |
|
142
|
+
@files_to_stay.each { | file_name | assert(!File.exists?(file_name)) }
|
143
|
+
@files_to_delete.each { | file_name | assert(!File.exists?(file_name)) }
|
144
|
+
@dirs.each { | dir_name | assert(!File.exists?(dir_name)) }
|
146
145
|
end
|
147
146
|
|
148
|
-
def
|
147
|
+
def test_dir_files
|
149
148
|
@dirs = ['/tmp/utilfiletest',
|
150
149
|
'/tmp/utilfiletest/subA',
|
151
150
|
'/tmp/utilfiletest/subA/subA1',
|
@@ -153,14 +152,14 @@ class TestUtilFile < Test::Unit::TestCase
|
|
153
152
|
'/tmp/utilfiletest/subB',
|
154
153
|
'/tmp/utilfiletest/subB/subB1',
|
155
154
|
'/tmp/utilfiletest/subB/subB1/subB1a']
|
156
|
-
@dirs.each { |
|
155
|
+
@dirs.each { | dir_name | FileUtils::makedirs(dir_name) }
|
157
156
|
@files = ['/tmp/utilfiletest/subA/blah.txt',
|
158
157
|
'/tmp/utilfiletest/subA/subA1/blah.txt',
|
159
158
|
'/tmp/utilfiletest/subA/subA2/blah.txt',
|
160
159
|
'/tmp/utilfiletest/subB/blah.txt',
|
161
160
|
'/tmp/utilfiletest/subB/subB1/blah.txt',
|
162
161
|
'/tmp/utilfiletest/subB/subB1/subB1a/blah.txt']
|
163
|
-
@files.each { | filename |
|
162
|
+
@files.each { | filename | create_test_file(filename, 'test content') }
|
164
163
|
#puts 'Dir.entries'
|
165
164
|
#puts Dir.entries('/tmp/utilfiletest/subA/subA1/')
|
166
165
|
#puts 'Dir.files'
|
@@ -168,11 +167,78 @@ class TestUtilFile < Test::Unit::TestCase
|
|
168
167
|
assert_equal(["blah.txt"], Dir.files('/tmp/utilfiletest/subA/subA1/'))
|
169
168
|
end
|
170
169
|
|
171
|
-
def
|
170
|
+
def test_file_extension
|
172
171
|
assert_equal('rb', File.extension('/test/file.rb'))
|
173
172
|
assert_equal(nil, File.extension('/test/file'))
|
174
173
|
assert_equal('rb', File.extension('/test/file.of.some.such.rb'))
|
175
174
|
end
|
176
175
|
end
|
177
176
|
|
177
|
+
class TestBackup < TempDirTest
|
178
178
|
|
179
|
+
def setup
|
180
|
+
super
|
181
|
+
@a_dir = make_sub_dir('a')
|
182
|
+
@b_dir = make_sub_dir('b')
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_backed_up_because_not_exists
|
186
|
+
src = make_sample_text_file('a')
|
187
|
+
dst = File.join(@b_dir, File.basename(src))
|
188
|
+
assert_equal(true, File.backup(src, dst))
|
189
|
+
assert_equal(true, File.exists?(dst))
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_not_backed_up_because_exists
|
193
|
+
src = make_sample_text_file('a')
|
194
|
+
dst = File.join(@b_dir, File.basename(src))
|
195
|
+
assert_equal(true, File.backup(src, dst))
|
196
|
+
assert_equal(false, File.backup(src, dst))
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_backed_up_because_exists_different_mtime
|
200
|
+
src = make_sample_text_file('a')
|
201
|
+
dst = File.join(@b_dir, File.basename(src))
|
202
|
+
assert_equal(true, File.backup(src, dst))
|
203
|
+
|
204
|
+
File.utime(0, 0, dst)
|
205
|
+
assert_equal(true, File.backup(src, dst))
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_backed_up_because_exists_different_size
|
209
|
+
src = make_sample_text_file('a')
|
210
|
+
dst = File.join(@b_dir, File.basename(src))
|
211
|
+
assert_equal(true, File.backup(src, dst))
|
212
|
+
|
213
|
+
File.open(dst, 'a+') do |f| f.print "bigger" end
|
214
|
+
assert_equal(true, File.backup(src, dst))
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_not_backed_up_because_exists_byte_diff_but_no_bincompare
|
218
|
+
src = make_sample_text_file('a')
|
219
|
+
dst = File.join(@b_dir, File.basename(src))
|
220
|
+
assert_equal(true, File.backup(src, dst))
|
221
|
+
|
222
|
+
guts = File.read(dst)
|
223
|
+
guts.reverse!
|
224
|
+
File.open(dst, 'w+') do |f| f.print guts end
|
225
|
+
File.utime(File.atime(src), File.mtime(src), dst)
|
226
|
+
assert_equal(false, File.backup(src, dst))
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_backed_up_because_exists_byte_diff_and_bincompare
|
230
|
+
src = make_sample_text_file('a')
|
231
|
+
dst = File.join(@b_dir, File.basename(src))
|
232
|
+
assert_equal(true, File.backup(src, dst))
|
233
|
+
|
234
|
+
guts = File.read(dst)
|
235
|
+
guts.reverse!
|
236
|
+
File.open(dst, 'w+') do |f| f.print guts end
|
237
|
+
File.utime(File.atime(src), File.mtime(src), dst)
|
238
|
+
assert_equal(true, File.backup(src, dst, true))
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
|
data/cl/util/test/stringtest.rb
CHANGED
@@ -7,13 +7,13 @@ class TestUtilString < Test::Unit::TestCase
|
|
7
7
|
def test_here_ltrim
|
8
8
|
test = <<-TEST
|
9
9
|
This is a test of the here_ltrim function.
|
10
|
-
|
10
|
+
Its purpose is to shift this whole paragraph to the left, removing
|
11
11
|
the indention.
|
12
12
|
TEST
|
13
13
|
|
14
14
|
expected = <<-EXP
|
15
15
|
This is a test of the here_ltrim function.
|
16
|
-
|
16
|
+
Its purpose is to shift this whole paragraph to the left, removing
|
17
17
|
the indention.
|
18
18
|
EXP
|
19
19
|
|
@@ -23,13 +23,13 @@ the indention.
|
|
23
23
|
def test_here_ltrim_indent
|
24
24
|
test = <<-TEST
|
25
25
|
This is a test of the here_ltrim function.
|
26
|
-
|
26
|
+
Its purpose is to shift this whole paragraph to the left, removing
|
27
27
|
the indention.
|
28
28
|
TEST
|
29
29
|
|
30
30
|
expected = <<-EXP
|
31
31
|
This is a test of the here_ltrim function.
|
32
|
-
|
32
|
+
Its purpose is to shift this whole paragraph to the left, removing
|
33
33
|
the indention.
|
34
34
|
EXP
|
35
35
|
|
data/cl/util/test.rb
CHANGED
@@ -32,23 +32,24 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
32
|
(based on BSD Open Source License)
|
33
33
|
=end
|
34
34
|
|
35
|
-
require '
|
36
|
-
require '
|
35
|
+
require File.dirname(__FILE__) + '/file'
|
36
|
+
require 'fileutils'
|
37
|
+
require 'tmpdir'
|
37
38
|
require 'test/unit'
|
38
39
|
|
39
40
|
class TempDirTest < Test::Unit::TestCase
|
40
|
-
def
|
41
|
-
@
|
41
|
+
def set_temp_dir
|
42
|
+
@temp_dir = Dir.mktmpdir
|
42
43
|
end
|
43
44
|
|
44
45
|
def setup
|
45
|
-
@
|
46
|
-
|
47
|
-
|
46
|
+
@file_name_inc = 0
|
47
|
+
set_temp_dir
|
48
|
+
FileUtils::makedirs(@temp_dir) if !FileTest.directory?(@temp_dir)
|
48
49
|
end
|
49
50
|
|
50
|
-
def
|
51
|
-
ClUtilFile.delTree(@
|
51
|
+
def teardown
|
52
|
+
ClUtilFile.delTree(@temp_dir)
|
52
53
|
end
|
53
54
|
|
54
55
|
# to ward off the new Test::Unit detection of classes with no test
|
@@ -57,31 +58,31 @@ class TempDirTest < Test::Unit::TestCase
|
|
57
58
|
super unless(self.class == TempDirTest)
|
58
59
|
end
|
59
60
|
|
60
|
-
def
|
61
|
-
newdirname = File.join(@
|
62
|
-
|
61
|
+
def make_sub_dir(dirname)
|
62
|
+
newdirname = File.join(@temp_dir, dirname)
|
63
|
+
FileUtils::makedirs(newdirname) if !FileTest.directory?(newdirname)
|
63
64
|
newdirname
|
64
65
|
end
|
65
66
|
|
66
|
-
def
|
67
|
-
|
67
|
+
def make_sample_text_file(dirname='', size=0)
|
68
|
+
crlf_length = 2
|
68
69
|
|
69
70
|
if size == 0
|
70
71
|
content = 'this is a sample file'
|
71
72
|
else
|
72
73
|
content = ''
|
73
|
-
(size -
|
74
|
+
(size - crlf_length).times do content << 'x' end
|
74
75
|
end
|
75
76
|
|
76
77
|
if dirname.empty?
|
77
|
-
|
78
|
+
sample_file_dir = @temp_dir
|
78
79
|
else
|
79
|
-
|
80
|
+
sample_file_dir = File.join(@temp_dir, dirname)
|
80
81
|
end
|
81
82
|
|
82
|
-
@
|
83
|
-
filename = File.join(
|
84
|
-
File.open(filename,
|
83
|
+
@file_name_inc += 1
|
84
|
+
filename = File.join(sample_file_dir, 'sample' + @file_name_inc.to_s + '.txt')
|
85
|
+
File.open(filename, 'w+') do |f|
|
85
86
|
f.puts content
|
86
87
|
end
|
87
88
|
filename
|
data/cl/util/util.rb
CHANGED
@@ -3,8 +3,8 @@ require 'cl/util/version'
|
|
3
3
|
# VERSION auto generated section
|
4
4
|
begin
|
5
5
|
require 'cl/util/version'
|
6
|
-
VERSION = CLabs::Version.new('2010', '
|
6
|
+
VERSION = CLabs::Version.new('2010', '132', '1')
|
7
7
|
rescue LoadError
|
8
|
-
VERSION = '2010.
|
8
|
+
VERSION = '2010.132.1'
|
9
9
|
end
|
10
10
|
# END_VERSION
|
data/cl/util/win.rb
CHANGED
@@ -32,7 +32,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
32
|
=end
|
33
33
|
require 'Win32API'
|
34
34
|
require 'win32ole'
|
35
|
-
require '
|
35
|
+
require File.dirname(__FILE__) + '/file'
|
36
36
|
|
37
37
|
# MENON Jean-Francois [Jean-Francois.MENON@meteo.fr]
|
38
38
|
# http://ruby-talk.com/41583
|
@@ -347,5 +347,4 @@ class File
|
|
347
347
|
STARTMENU = "StartMenu"
|
348
348
|
STARTUP = "Startup"
|
349
349
|
TEMPLATES = "Templates"
|
350
|
-
end
|
351
|
-
|
350
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2010
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 2010.
|
7
|
+
- 132
|
8
|
+
- 1
|
9
|
+
version: 2010.132.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- chrismo
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-12 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- cl/util/test/dirsizetest.rb
|
51
51
|
- cl/util/test/filetest.rb
|
52
52
|
- cl/util/test/installtest.rb
|
53
|
+
- cl/util/test/nettest.rb
|
53
54
|
- cl/util/test/progresstest.rb
|
54
55
|
- cl/util/test/stringtest.rb
|
55
56
|
- cl/util/test/versiontest.rb
|