rubysl-ftools 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/ftools.rb +1 -0
- data/lib/rubysl/ftools.rb +2 -0
- data/lib/rubysl/ftools/ftools.rb +261 -0
- data/lib/rubysl/ftools/version.rb +5 -0
- data/rubysl-ftools.gemspec +23 -0
- data/spec/catname_spec.rb +18 -0
- data/spec/chmod_spec.rb +28 -0
- data/spec/compare_spec.rb +29 -0
- data/spec/copy_spec.rb +33 -0
- data/spec/install_spec.rb +24 -0
- data/spec/makedirs_spec.rb +23 -0
- data/spec/move_spec.rb +32 -0
- data/spec/safe_unlink_spec.rb +25 -0
- data/spec/syscopy_spec.rb +33 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74b4dfc8ddaf27b36022f78e7253893aa3f6a700
|
4
|
+
data.tar.gz: e5e8f66accf3b1610355fcf5c1bb1f612a5f1558
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d45833925ee35c79188d5e4af0a9b360fa01048dc36f423d8efecbf1995eec9b8739d1be524b2b0f81fc2f8786b8868488e20d80c5f27a48e039099258973ec
|
7
|
+
data.tar.gz: 2ddf2e33d6d8dcb34d4f5a6da6ac99f8b63226d8cb84c43c335480396904f526b72f0dd33b4dba7aa6b3753848f27c7f29592989a514dd1014cadf63f331cf78
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2013, Brian Shirai
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the library nor the names of its contributors may be
|
13
|
+
used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
|
20
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
21
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
23
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
25
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rubysl::Ftools
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rubysl-ftools'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rubysl-ftools
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/ftools.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/ftools"
|
@@ -0,0 +1,261 @@
|
|
1
|
+
#
|
2
|
+
# = ftools.rb: Extra tools for the File class
|
3
|
+
#
|
4
|
+
# Author:: WATANABE, Hirofumi
|
5
|
+
# Documentation:: Zachary Landau
|
6
|
+
#
|
7
|
+
# This library can be distributed under the terms of the Ruby license.
|
8
|
+
# You can freely distribute/modify this library.
|
9
|
+
#
|
10
|
+
# It is included in the Ruby standard library.
|
11
|
+
#
|
12
|
+
# == Description
|
13
|
+
#
|
14
|
+
# ftools adds several (class, not instance) methods to the File class, for
|
15
|
+
# copying, moving, deleting, installing, and comparing files, as well as
|
16
|
+
# creating a directory path. See the File class for details.
|
17
|
+
#
|
18
|
+
# FileUtils contains all or nearly all the same functionality and more, and
|
19
|
+
# is a recommended option over ftools
|
20
|
+
#
|
21
|
+
# When you
|
22
|
+
#
|
23
|
+
# require 'ftools'
|
24
|
+
#
|
25
|
+
# then the File class aquires some utility methods for copying, moving, and
|
26
|
+
# deleting files, and more.
|
27
|
+
#
|
28
|
+
# See the method descriptions below, and consider using FileUtils as it is
|
29
|
+
# more comprehensive.
|
30
|
+
#
|
31
|
+
class File
|
32
|
+
end
|
33
|
+
|
34
|
+
class << File
|
35
|
+
|
36
|
+
BUFSIZE = 8 * 1024
|
37
|
+
|
38
|
+
#
|
39
|
+
# If +to+ is a valid directory, +from+ will be appended to +to+, adding
|
40
|
+
# and escaping backslashes as necessary. Otherwise, +to+ will be returned.
|
41
|
+
# Useful for appending +from+ to +to+ only if the filename was not specified
|
42
|
+
# in +to+.
|
43
|
+
#
|
44
|
+
def catname(from, to)
|
45
|
+
if directory? to
|
46
|
+
join to.sub(%r([/\\]$), ''), basename(from)
|
47
|
+
else
|
48
|
+
to
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Copies a file +from+ to +to+. If +to+ is a directory, copies +from+
|
54
|
+
# to <tt>to/from</tt>.
|
55
|
+
#
|
56
|
+
def syscopy(from, to)
|
57
|
+
to = catname(from, to)
|
58
|
+
|
59
|
+
fmode = stat(from).mode
|
60
|
+
tpath = to
|
61
|
+
not_exist = !exist?(tpath)
|
62
|
+
|
63
|
+
from = open(from, "rb")
|
64
|
+
to = open(to, "wb")
|
65
|
+
|
66
|
+
begin
|
67
|
+
while true
|
68
|
+
to.syswrite from.sysread(BUFSIZE)
|
69
|
+
end
|
70
|
+
rescue EOFError
|
71
|
+
ret = true
|
72
|
+
rescue
|
73
|
+
ret = false
|
74
|
+
ensure
|
75
|
+
to.close
|
76
|
+
from.close
|
77
|
+
end
|
78
|
+
chmod(fmode, tpath) if not_exist
|
79
|
+
ret
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Copies a file +from+ to +to+ using #syscopy. If +to+ is a directory,
|
84
|
+
# copies +from+ to <tt>to/from</tt>. If +verbose+ is true, <tt>from -> to</tt>
|
85
|
+
# is printed.
|
86
|
+
#
|
87
|
+
def copy(from, to, verbose = false)
|
88
|
+
$stderr.print from, " -> ", catname(from, to), "\n" if verbose
|
89
|
+
syscopy from, to
|
90
|
+
end
|
91
|
+
|
92
|
+
alias cp copy
|
93
|
+
|
94
|
+
#
|
95
|
+
# Moves a file +from+ to +to+ using #syscopy. If +to+ is a directory,
|
96
|
+
# copies from +from+ to <tt>to/from</tt>. If +verbose+ is true, <tt>from ->
|
97
|
+
# to</tt> is printed.
|
98
|
+
#
|
99
|
+
def move(from, to, verbose = false)
|
100
|
+
to = catname(from, to)
|
101
|
+
$stderr.print from, " -> ", to, "\n" if verbose
|
102
|
+
|
103
|
+
if RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ and file? to
|
104
|
+
unlink to
|
105
|
+
end
|
106
|
+
fstat = stat(from)
|
107
|
+
begin
|
108
|
+
rename from, to
|
109
|
+
rescue
|
110
|
+
begin
|
111
|
+
symlink readlink(from), to and unlink from
|
112
|
+
rescue
|
113
|
+
from_stat = stat(from)
|
114
|
+
syscopy from, to and unlink from
|
115
|
+
utime(from_stat.atime, from_stat.mtime, to)
|
116
|
+
begin
|
117
|
+
chown(fstat.uid, fstat.gid, to)
|
118
|
+
rescue
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
alias mv move
|
125
|
+
|
126
|
+
#
|
127
|
+
# Returns +true+ if and only if the contents of files +from+ and +to+ are
|
128
|
+
# identical. If +verbose+ is +true+, <tt>from <=> to</tt> is printed.
|
129
|
+
#
|
130
|
+
def compare(from, to, verbose = false)
|
131
|
+
$stderr.print from, " <=> ", to, "\n" if verbose
|
132
|
+
|
133
|
+
return false if stat(from).size != stat(to).size
|
134
|
+
|
135
|
+
from = open(from, "rb")
|
136
|
+
to = open(to, "rb")
|
137
|
+
|
138
|
+
ret = false
|
139
|
+
fr = tr = ''
|
140
|
+
|
141
|
+
begin
|
142
|
+
while fr == tr
|
143
|
+
fr = from.read(BUFSIZE)
|
144
|
+
if fr
|
145
|
+
tr = to.read(fr.size)
|
146
|
+
else
|
147
|
+
ret = to.read(BUFSIZE)
|
148
|
+
ret = !ret || ret.length == 0
|
149
|
+
break
|
150
|
+
end
|
151
|
+
end
|
152
|
+
rescue
|
153
|
+
ret = false
|
154
|
+
ensure
|
155
|
+
to.close
|
156
|
+
from.close
|
157
|
+
end
|
158
|
+
ret
|
159
|
+
end
|
160
|
+
|
161
|
+
alias cmp compare
|
162
|
+
|
163
|
+
#
|
164
|
+
# Removes a list of files. Each parameter should be the name of the file to
|
165
|
+
# delete. If the last parameter isn't a String, verbose mode will be enabled.
|
166
|
+
# Returns the number of files deleted.
|
167
|
+
#
|
168
|
+
def safe_unlink(*files)
|
169
|
+
verbose = if files[-1].is_a? String then false else files.pop end
|
170
|
+
files.each do |file|
|
171
|
+
begin
|
172
|
+
unlink file
|
173
|
+
$stderr.print "removing ", file, "\n" if verbose
|
174
|
+
rescue Errno::EACCES # for Windows
|
175
|
+
continue if symlink? file
|
176
|
+
begin
|
177
|
+
mode = stat(file).mode
|
178
|
+
o_chmod mode | 0200, file
|
179
|
+
unlink file
|
180
|
+
$stderr.print "removing ", file, "\n" if verbose
|
181
|
+
rescue
|
182
|
+
o_chmod mode, file rescue nil
|
183
|
+
end
|
184
|
+
rescue
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
alias rm_f safe_unlink
|
190
|
+
|
191
|
+
#
|
192
|
+
# Creates a directory and all its parent directories.
|
193
|
+
# For example,
|
194
|
+
#
|
195
|
+
# File.makedirs '/usr/lib/ruby'
|
196
|
+
#
|
197
|
+
# causes the following directories to be made, if they do not exist.
|
198
|
+
# * /usr
|
199
|
+
# * /usr/lib
|
200
|
+
# * /usr/lib/ruby
|
201
|
+
#
|
202
|
+
# You can pass several directories, each as a parameter. If the last
|
203
|
+
# parameter isn't a String, verbose mode will be enabled.
|
204
|
+
#
|
205
|
+
def makedirs(*dirs)
|
206
|
+
verbose = if dirs[-1].is_a? String then false else dirs.pop end
|
207
|
+
mode = 0755
|
208
|
+
for dir in dirs
|
209
|
+
parent = dirname(dir)
|
210
|
+
next if parent == dir or directory? dir
|
211
|
+
makedirs parent unless directory? parent
|
212
|
+
$stderr.print "mkdir ", dir, "\n" if verbose
|
213
|
+
if basename(dir) != ""
|
214
|
+
begin
|
215
|
+
Dir.mkdir dir, mode
|
216
|
+
rescue SystemCallError
|
217
|
+
raise unless directory? dir
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
alias mkpath makedirs
|
224
|
+
|
225
|
+
alias o_chmod chmod
|
226
|
+
|
227
|
+
vsave, $VERBOSE = $VERBOSE, false
|
228
|
+
|
229
|
+
#
|
230
|
+
# Changes permission bits on +files+ to the bit pattern represented
|
231
|
+
# by +mode+. If the last parameter isn't a String, verbose mode will
|
232
|
+
# be enabled.
|
233
|
+
#
|
234
|
+
# File.chmod 0755, 'somecommand'
|
235
|
+
# File.chmod 0644, 'my.rb', 'your.rb', true
|
236
|
+
#
|
237
|
+
def chmod(mode, *files)
|
238
|
+
verbose = if files[-1].is_a? String then false else files.pop end
|
239
|
+
$stderr.printf "chmod %04o %s\n", mode, files.join(" ") if verbose
|
240
|
+
o_chmod mode, *files
|
241
|
+
end
|
242
|
+
$VERBOSE = vsave
|
243
|
+
|
244
|
+
#
|
245
|
+
# If +src+ is not the same as +dest+, copies it and changes the permission
|
246
|
+
# mode to +mode+. If +dest+ is a directory, destination is <tt>dest/src</tt>.
|
247
|
+
# If +mode+ is not set, default is used. If +verbose+ is set to true, the
|
248
|
+
# name of each file copied will be printed.
|
249
|
+
#
|
250
|
+
def install(from, to, mode = nil, verbose = false)
|
251
|
+
to = catname(from, to)
|
252
|
+
unless exist? to and cmp from, to
|
253
|
+
safe_unlink to if exist? to
|
254
|
+
cp from, to, verbose
|
255
|
+
chmod mode, to, verbose if mode
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
# vi:set sw=2:
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/ftools/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-ftools"
|
6
|
+
spec.version = RubySL::FTools::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library ftools.}
|
10
|
+
spec.summary = %q{Ruby standard library ftools.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-ftools"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
describe "File.catname" do
|
6
|
+
it "returns the 2nd arg if it's not a directory" do
|
7
|
+
File.catname("blah", "/etc/passwd").should == "/etc/passwd"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "uses File.join with the args" do
|
11
|
+
File.catname("passwd", ".").should == "./passwd"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "uses File.basename on the 1st arg before joining" do
|
15
|
+
File.catname("etc/passwd", ".").should == "./passwd"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/chmod_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
# the tests below are windows-hostile
|
4
|
+
platform_is_not :windows do
|
5
|
+
require 'ftools'
|
6
|
+
|
7
|
+
describe "File.chmod" do
|
8
|
+
before(:each) do
|
9
|
+
(1..2).each do |n|
|
10
|
+
system "echo 'hello rubinius' > chmod_test_#{n}"
|
11
|
+
system "chmod 0777 chmod_test_#{n}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
(1..2).each { |n| File.unlink "chmod_test_#{n}" rescue nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "changes the mode to 1st arg for files in 2nd arg" do
|
20
|
+
`ls -l chmod_test_1`.should =~ /^-rwxrwxrwx/
|
21
|
+
`ls -l chmod_test_2`.should =~ /^-rwxrwxrwx/
|
22
|
+
File.chmod 0644, "chmod_test_1", "chmod_test_2"
|
23
|
+
`ls -l chmod_test_1`.should =~ /^-rw-r--r--/
|
24
|
+
`ls -l chmod_test_2`.should =~ /^-rw-r--r--/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
describe "File.compare" do
|
6
|
+
before(:each) do
|
7
|
+
(1..3).to_a.each do |n|
|
8
|
+
if n == 3
|
9
|
+
system "echo 'hello mri' > compare_test_#{n}"
|
10
|
+
else
|
11
|
+
system "echo 'hello rubinius' > compare_test_#{n}"
|
12
|
+
end
|
13
|
+
system "chmod a+x compare_test_#{n}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
(1..3).to_a.each { |n| File.unlink "compare_test_#{n}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
it "compares the file at 1st arg to the file at 2nd arg" do
|
22
|
+
File.compare("compare_test_1", "compare_test_2").should == true
|
23
|
+
File.compare("compare_test_2", "compare_test_1").should == true
|
24
|
+
|
25
|
+
File.compare("compare_test_1", "compare_test_3").should == false
|
26
|
+
File.compare("compare_test_2", "compare_test_3").should == false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/copy_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
describe "File.copy" do
|
6
|
+
before(:each) do
|
7
|
+
File.open('copy_test', 'w+') do |f|
|
8
|
+
f.puts('hello rubinius')
|
9
|
+
end
|
10
|
+
platform_is_not :windows do
|
11
|
+
system "chmod a+x copy_test"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
File.unlink "copy_test"
|
17
|
+
File.unlink "copy_test_dest" rescue nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "copies the file at 1st arg to the file at 2nd arg" do
|
21
|
+
File.copy("copy_test", "copy_test_dest")
|
22
|
+
fd = File.open("copy_test_dest")
|
23
|
+
data = fd.read
|
24
|
+
data.should == "hello rubinius\n"
|
25
|
+
fd.close
|
26
|
+
|
27
|
+
omode = File.stat("copy_test").mode
|
28
|
+
mode = File.stat("copy_test_dest").mode
|
29
|
+
|
30
|
+
omode.should == mode
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
# the tests below are windows-hostile
|
6
|
+
platform_is_not :windows do
|
7
|
+
describe "File.install" do
|
8
|
+
before(:each) do
|
9
|
+
system "echo 'hello rubinius' > install_test_1"
|
10
|
+
system "chmod 0777 install_test_1"
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
(1..2).each { |n| File.unlink "install_test_#{n}" rescue nil }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "changes the mode to 1st arg for files in 2nd arg" do
|
18
|
+
`ls -l install_test_1`.should =~ /^-rwxrwxrwx/
|
19
|
+
File.install "install_test_1", "install_test_2", 0644
|
20
|
+
`ls -l install_test_2`.should =~ /^-rw-r--r--/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
describe "File.makedirs" do
|
6
|
+
before :each do
|
7
|
+
@dir = tmp "file_makedirs"
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:each) do
|
11
|
+
rm_r @dir
|
12
|
+
end
|
13
|
+
|
14
|
+
it "creates the dirs from arg" do
|
15
|
+
File.exist?(@dir).should == false
|
16
|
+
File.makedirs("#{@dir}/second_dir")
|
17
|
+
File.exist?(@dir).should == true
|
18
|
+
File.directory?(@dir).should == true
|
19
|
+
File.exist?("#{@dir}/second_dir").should == true
|
20
|
+
File.directory?("#{@dir}/second_dir").should == true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/move_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
describe "File.move" do
|
6
|
+
before(:each) do
|
7
|
+
File.open('move_test', 'w+') do |f|
|
8
|
+
f.puts('hello rubinius')
|
9
|
+
end
|
10
|
+
platform_is_not :windows do
|
11
|
+
system "chmod a+x move_test"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
File.unlink "move_test_dest"
|
17
|
+
File.unlink "move_test" rescue nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "moves the file at 1st arg to the file at 2nd arg" do
|
21
|
+
omode = File.stat("move_test").mode
|
22
|
+
File.move("move_test", "move_test_dest")
|
23
|
+
fd = File.open("move_test_dest")
|
24
|
+
data = fd.read
|
25
|
+
data.should == "hello rubinius\n"
|
26
|
+
fd.close
|
27
|
+
mode = File.stat("move_test_dest").mode
|
28
|
+
|
29
|
+
omode.should == mode
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
describe "File.safe_unlink" do
|
6
|
+
before(:each) do
|
7
|
+
(1..2).each do |n|
|
8
|
+
system "echo 'hello rubinius' > safe_unlink_test_#{n}"
|
9
|
+
system "chmod 0777 safe_unlink_test_#{n}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
(1..2).each { |n| File.unlink "safe_unlink_test_#{n}" rescue nil }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "deletes the files in arg and returns an array of files deleted" do
|
18
|
+
File.exist?("safe_unlink_test_1").should == true
|
19
|
+
File.exist?("safe_unlink_test_2").should == true
|
20
|
+
File.safe_unlink("safe_unlink_test_1", "safe_unlink_test_2").should == ["safe_unlink_test_1", "safe_unlink_test_2"]
|
21
|
+
File.exist?("safe_unlink_test_1").should == false
|
22
|
+
File.exist?("safe_unlink_test_2").should == false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
ruby_version_is ""..."1.9" do
|
2
|
+
|
3
|
+
require 'ftools'
|
4
|
+
|
5
|
+
describe "File.syscopy" do
|
6
|
+
before(:each) do
|
7
|
+
File.open('syscopy_test', 'w+') do |f|
|
8
|
+
f.puts('hello rubinius')
|
9
|
+
end
|
10
|
+
platform_is_not :windows do
|
11
|
+
system "chmod a+x syscopy_test"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
File.unlink "syscopy_test"
|
17
|
+
File.unlink "syscopy_test_dest" rescue nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "copies the file at 1st arg to the file at 2nd arg" do
|
21
|
+
File.syscopy("syscopy_test", "syscopy_test_dest")
|
22
|
+
fd = File.open("syscopy_test_dest")
|
23
|
+
data = fd.read
|
24
|
+
data.should == "hello rubinius\n"
|
25
|
+
fd.close
|
26
|
+
|
27
|
+
omode = File.stat("syscopy_test").mode
|
28
|
+
mode = File.stat("syscopy_test_dest").mode
|
29
|
+
|
30
|
+
omode.should == mode
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubysl-ftools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Shirai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubysl-prettyprint
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: Ruby standard library ftools.
|
70
|
+
email:
|
71
|
+
- brixen@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/ftools.rb
|
83
|
+
- lib/rubysl/ftools.rb
|
84
|
+
- lib/rubysl/ftools/ftools.rb
|
85
|
+
- lib/rubysl/ftools/version.rb
|
86
|
+
- rubysl-ftools.gemspec
|
87
|
+
- spec/catname_spec.rb
|
88
|
+
- spec/chmod_spec.rb
|
89
|
+
- spec/compare_spec.rb
|
90
|
+
- spec/copy_spec.rb
|
91
|
+
- spec/install_spec.rb
|
92
|
+
- spec/makedirs_spec.rb
|
93
|
+
- spec/move_spec.rb
|
94
|
+
- spec/safe_unlink_spec.rb
|
95
|
+
- spec/syscopy_spec.rb
|
96
|
+
homepage: https://github.com/rubysl/rubysl-ftools
|
97
|
+
licenses:
|
98
|
+
- BSD
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Ruby standard library ftools.
|
120
|
+
test_files:
|
121
|
+
- spec/catname_spec.rb
|
122
|
+
- spec/chmod_spec.rb
|
123
|
+
- spec/compare_spec.rb
|
124
|
+
- spec/copy_spec.rb
|
125
|
+
- spec/install_spec.rb
|
126
|
+
- spec/makedirs_spec.rb
|
127
|
+
- spec/move_spec.rb
|
128
|
+
- spec/safe_unlink_spec.rb
|
129
|
+
- spec/syscopy_spec.rb
|
130
|
+
has_rdoc:
|