rsense-core 0.5.6 → 0.5.8
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 +4 -4
- data/lib/rsense.jar +0 -0
- data/lib/rsense/core/version.rb +1 -1
- data/src/org/cx4a/rsense/ruby/Ruby.java +9 -4
- data/src/org/cx4a/rsense/ruby/RubyClass.java +4 -4
- data/src/resources/org/cx4a/rsense/rsense.properties +1 -1
- data/stubs/1.8/_builtin.rb +46 -0
- data/stubs/1.8/delegate.rb +183 -0
- data/stubs/1.8/etc.rb +41 -0
- data/stubs/1.8/fileutils.rb +834 -0
- data/stubs/1.8/find.rb +43 -0
- data/stubs/1.8/pathname.rb +562 -0
- data/stubs/1.8/tempfile.rb +406 -0
- data/stubs/1.8/tmpdir.rb +130 -0
- metadata +9 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea7d550cad6e3326f281dfe2d74b45490482a076
|
|
4
|
+
data.tar.gz: de4e8c69f48ae9d77e5348974c3c047e430eabd2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d694a57f2ae66b9fa73a6a236caed7008b768816a7a1cbde5d0d9caa806af00a747b1e99f65c0981e38725703f731a9c7f42c3e0cf88b7501487e517d85e5846
|
|
7
|
+
data.tar.gz: 0a25325106b8d8cea07e02f2a87ffcd5c8ca5d399a1a63649bdcb6fc7109ce5045ed9b2d9de0a4f3874e8270592e85e09d590182aaefb986a220cd3094277d7a
|
data/lib/rsense.jar
CHANGED
|
Binary file
|
data/lib/rsense/core/version.rb
CHANGED
|
@@ -17,7 +17,7 @@ public class Ruby {
|
|
|
17
17
|
private Context context;
|
|
18
18
|
private ObjectAllocator allocator;
|
|
19
19
|
private RubyModule kernelModule;
|
|
20
|
-
private RubyClass objectClass, moduleClass, classClass,
|
|
20
|
+
private RubyClass basicObjectClass, objectClass, moduleClass, classClass,
|
|
21
21
|
numericClass, integerClass, fixnumClass, bignumClass,
|
|
22
22
|
floatClass, stringClass, symbolClass,
|
|
23
23
|
booleanClass, trueClass, falseClass, nilClass,
|
|
@@ -32,20 +32,24 @@ public class Ruby {
|
|
|
32
32
|
public Ruby() {
|
|
33
33
|
allocator = new DefaultObjectAllocator();
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
basicObjectClass = RubyClass.newBootClass(this, "BasicObject", null);
|
|
36
|
+
objectClass = RubyClass.newBootClass(this, "Object", basicObjectClass);
|
|
36
37
|
moduleClass = RubyClass.newBootClass(this, "Module", objectClass);
|
|
37
38
|
classClass = RubyClass.newBootClass(this, "Class", moduleClass);
|
|
38
39
|
|
|
40
|
+
basicObjectClass.setMetaClass(classClass);
|
|
39
41
|
objectClass.setMetaClass(classClass);
|
|
40
42
|
moduleClass.setMetaClass(classClass);
|
|
41
43
|
classClass.setMetaClass(classClass);
|
|
42
44
|
|
|
43
45
|
RubyClass metaClass;
|
|
46
|
+
metaClass = basicObjectClass.makeMetaClass(classClass);
|
|
44
47
|
metaClass = objectClass.makeMetaClass(classClass);
|
|
45
48
|
metaClass = moduleClass.makeMetaClass(metaClass);
|
|
46
49
|
metaClass = classClass.makeMetaClass(metaClass);
|
|
47
50
|
|
|
48
51
|
kernelModule = RubyModule.newModule(this, "Kernel", null);
|
|
52
|
+
basicObjectClass.includeModule(kernelModule);
|
|
49
53
|
objectClass.includeModule(kernelModule);
|
|
50
54
|
numericClass = RubyClass.newClass(this, "Numeric", objectClass);
|
|
51
55
|
integerClass = RubyClass.newClass(this, "Integer", numericClass);
|
|
@@ -68,6 +72,7 @@ public class Ruby {
|
|
|
68
72
|
fatalClass = RubyClass.newClass(this, "fatal", exceptionClass);
|
|
69
73
|
|
|
70
74
|
objectClass.setConstant("Kernel", kernelModule);
|
|
75
|
+
objectClass.setConstant("BasicObject", basicObjectClass);
|
|
71
76
|
objectClass.setConstant("Object", objectClass);
|
|
72
77
|
objectClass.setConstant("Module", moduleClass);
|
|
73
78
|
objectClass.setConstant("Class", classClass);
|
|
@@ -116,11 +121,11 @@ public class Ruby {
|
|
|
116
121
|
public void setGlobalVar(String name, IRubyObject value) {
|
|
117
122
|
globalVars.put(name, value);
|
|
118
123
|
}
|
|
119
|
-
|
|
124
|
+
|
|
120
125
|
public IRubyObject newInstance(RubyClass klass) {
|
|
121
126
|
return allocator.allocate(this, klass);
|
|
122
127
|
}
|
|
123
|
-
|
|
128
|
+
|
|
124
129
|
public boolean isInstanceOf(IRubyObject object, RubyModule klass) {
|
|
125
130
|
return object.getMetaClass() == klass;
|
|
126
131
|
}
|
|
@@ -17,11 +17,11 @@ public class RubyClass extends RubyModule {
|
|
|
17
17
|
public static RubyClass newClassWithLocation(Ruby runtime, String baseName, RubyClass superClass, SourceLocation location) {
|
|
18
18
|
return newClassWithLocation(runtime, baseName, superClass, null, location);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
public static RubyClass newClass(Ruby runtime, String baseName, RubyClass superClass, RubyModule parent) {
|
|
22
22
|
return newClassWithLocation(runtime, baseName, superClass, parent, null);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
public static RubyClass newClassWithLocation(Ruby runtime, String baseName, RubyClass superClass, RubyModule parent, SourceLocation location) {
|
|
26
26
|
if (superClass == null) {
|
|
27
27
|
superClass = runtime.getObject();
|
|
@@ -42,7 +42,7 @@ public class RubyClass extends RubyModule {
|
|
|
42
42
|
protected RubyClass(Ruby runtime, RubyClass superClass) {
|
|
43
43
|
this(runtime, superClass, null);
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
protected RubyClass(Ruby runtime, RubyClass superClass, RubyModule parent) {
|
|
47
47
|
this(runtime, runtime.getClassClass(), superClass, parent, null);
|
|
48
48
|
}
|
|
@@ -59,7 +59,7 @@ public class RubyClass extends RubyModule {
|
|
|
59
59
|
public RubyClass getRealClass() {
|
|
60
60
|
return this;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
public RubyClass getSuperClass() {
|
|
64
64
|
return superClass;
|
|
65
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
rsense.version = 0.5.
|
|
1
|
+
rsense.version = 0.5.8
|
data/stubs/1.8/_builtin.rb
CHANGED
|
@@ -1920,6 +1920,52 @@ class Numeric
|
|
|
1920
1920
|
def zero?() BOOLEAN end
|
|
1921
1921
|
end
|
|
1922
1922
|
|
|
1923
|
+
class BasicObject
|
|
1924
|
+
##% ==(a) -> Boolean
|
|
1925
|
+
def ==(other) BOOLEAN end
|
|
1926
|
+
##% ===(a) -> Boolean
|
|
1927
|
+
def __id__() 0 end
|
|
1928
|
+
alias :object_id :__id__
|
|
1929
|
+
|
|
1930
|
+
##% send(String or Symbol, *a) -> Object
|
|
1931
|
+
def send(name, *args) end
|
|
1932
|
+
##% eql?(a) -> Boolean
|
|
1933
|
+
def eql?(other) BOOLEAN end
|
|
1934
|
+
##% equal?(a) -> Boolean
|
|
1935
|
+
def equal?(other) BOOLEAN end
|
|
1936
|
+
##% instance_eval(String, ?String, ?Integer) -> Object
|
|
1937
|
+
##% instance_eval() {Object -> ?} -> Object
|
|
1938
|
+
def instance_eval(expr, filename = "(eval)", lineno = 1) Object.new end
|
|
1939
|
+
def method_missing(name, *args) end
|
|
1940
|
+
##% singleton_methods(?Boolean) -> Array<String>
|
|
1941
|
+
def singleton_methods(inherited_too = true) [''] end
|
|
1942
|
+
def self.new()
|
|
1943
|
+
#This is a stub, used for indexing
|
|
1944
|
+
end
|
|
1945
|
+
def !=(other)
|
|
1946
|
+
self == other ? false : true
|
|
1947
|
+
end
|
|
1948
|
+
|
|
1949
|
+
def ! obj
|
|
1950
|
+
if obj
|
|
1951
|
+
true
|
|
1952
|
+
else
|
|
1953
|
+
false
|
|
1954
|
+
end
|
|
1955
|
+
end
|
|
1956
|
+
|
|
1957
|
+
def singleton_method_added(name) end
|
|
1958
|
+
|
|
1959
|
+
def singleton_method_removed(name) end
|
|
1960
|
+
|
|
1961
|
+
def singleton_method_undefined(name) end
|
|
1962
|
+
|
|
1963
|
+
def instance_exec(*args)
|
|
1964
|
+
Object.new
|
|
1965
|
+
end
|
|
1966
|
+
end
|
|
1967
|
+
|
|
1968
|
+
|
|
1923
1969
|
class Object
|
|
1924
1970
|
##% ==(a) -> Boolean
|
|
1925
1971
|
def ==(other) BOOLEAN end
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
class Delegator < BasicObject
|
|
2
|
+
kernel = ::Kernel.dup
|
|
3
|
+
kernel.class_eval do
|
|
4
|
+
alias __raise__ raise
|
|
5
|
+
[:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash].each do |m|
|
|
6
|
+
undef_method m
|
|
7
|
+
end
|
|
8
|
+
private_instance_methods.each do |m|
|
|
9
|
+
if /\Ablock_given\?\z|iterator\?\z|\A__.*__\z/ =~ m
|
|
10
|
+
next
|
|
11
|
+
end
|
|
12
|
+
undef_method m
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
include kernel
|
|
16
|
+
|
|
17
|
+
# :stopdoc:
|
|
18
|
+
def self.const_missing(n)
|
|
19
|
+
::Object.const_get(n)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def initialize(obj)
|
|
23
|
+
__setobj__(obj)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def method_missing(m, *args, &block)
|
|
27
|
+
r = true
|
|
28
|
+
target = self.__getobj__ {r = false}
|
|
29
|
+
begin
|
|
30
|
+
if r && target.respond_to?(m)
|
|
31
|
+
target.__send__(m, *args, &block)
|
|
32
|
+
elsif ::Kernel.respond_to?(m, true)
|
|
33
|
+
::Kernel.instance_method(m).bind(self).(*args, &block)
|
|
34
|
+
else
|
|
35
|
+
super(m, *args, &block)
|
|
36
|
+
end
|
|
37
|
+
ensure
|
|
38
|
+
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:(?:#{[__LINE__-7, __LINE__-5, __LINE__-3].join('|')}):"o =~ t} if $@
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def respond_to_missing?(m, include_private)
|
|
43
|
+
r = true
|
|
44
|
+
target = self.__getobj__ {r = false}
|
|
45
|
+
r &&= target.respond_to?(m, include_private)
|
|
46
|
+
if r && include_private && !target.respond_to?(m, false)
|
|
47
|
+
warn "#{caller(3)[0]}: delegator does not forward private method \##{m}"
|
|
48
|
+
return false
|
|
49
|
+
end
|
|
50
|
+
r
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def methods(all=true)
|
|
54
|
+
__getobj__.methods(all) | super
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def public_methods(all=true)
|
|
58
|
+
__getobj__.public_methods(all) | super
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def protected_methods(all=true)
|
|
62
|
+
__getobj__.protected_methods(all) | super
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def ==(obj)
|
|
66
|
+
return true if obj.equal?(self)
|
|
67
|
+
self.__getobj__ == obj
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def !=(obj)
|
|
71
|
+
return false if obj.equal?(self)
|
|
72
|
+
__getobj__ != obj
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def !
|
|
76
|
+
!__getobj__
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def __getobj__
|
|
80
|
+
__raise__ ::NotImplementedError, "need to define `__getobj__'"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def __setobj__(obj)
|
|
84
|
+
__raise__ ::NotImplementedError, "need to define `__setobj__'"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def marshal_dump
|
|
88
|
+
ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
|
|
89
|
+
[
|
|
90
|
+
:__v2__,
|
|
91
|
+
ivars, ivars.map{|var| instance_variable_get(var)},
|
|
92
|
+
__getobj__
|
|
93
|
+
]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def marshal_load(data)
|
|
97
|
+
version, vars, values, obj = data
|
|
98
|
+
if version == :__v2__
|
|
99
|
+
vars.each_with_index{|var, i| instance_variable_set(var, values[i])}
|
|
100
|
+
__setobj__(obj)
|
|
101
|
+
else
|
|
102
|
+
__setobj__(data)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def initialize_clone(obj) # :nodoc:
|
|
107
|
+
self.__setobj__(obj.__getobj__.clone)
|
|
108
|
+
end
|
|
109
|
+
def initialize_dup(obj) # :nodoc:
|
|
110
|
+
self.__setobj__(obj.__getobj__.dup)
|
|
111
|
+
end
|
|
112
|
+
private :initialize_clone, :initialize_dup
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
[:trust, :untrust, :taint, :untaint, :freeze].each do |method|
|
|
116
|
+
define_method method do
|
|
117
|
+
__getobj__.send(method)
|
|
118
|
+
super()
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
@delegator_api = self.public_instance_methods
|
|
123
|
+
def self.public_api # :nodoc:
|
|
124
|
+
@delegator_api
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
class SimpleDelegator<Delegator
|
|
129
|
+
|
|
130
|
+
def __getobj__
|
|
131
|
+
unless defined?(@delegate_sd_obj)
|
|
132
|
+
return yield if block_given?
|
|
133
|
+
__raise__ ::ArgumentError, "not delegated"
|
|
134
|
+
end
|
|
135
|
+
@delegate_sd_obj
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def __setobj__(obj)
|
|
139
|
+
__raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
|
|
140
|
+
@delegate_sd_obj = obj
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def Delegator.delegating_block(mid) # :nodoc:
|
|
145
|
+
lambda do |*args, &block|
|
|
146
|
+
target = self.__getobj__
|
|
147
|
+
begin
|
|
148
|
+
target.__send__(mid, *args, &block)
|
|
149
|
+
ensure
|
|
150
|
+
$@.delete_if {|t| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o =~ t} if $@
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def DelegateClass(superclass)
|
|
156
|
+
klass = Class.new(Delegator)
|
|
157
|
+
methods = superclass.instance_methods
|
|
158
|
+
methods -= ::Delegator.public_api
|
|
159
|
+
methods -= [:to_s,:inspect,:=~,:!~,:===]
|
|
160
|
+
klass.module_eval do
|
|
161
|
+
def __getobj__ # :nodoc:
|
|
162
|
+
unless defined?(@delegate_dc_obj)
|
|
163
|
+
return yield if block_given?
|
|
164
|
+
__raise__ ::ArgumentError, "not delegated"
|
|
165
|
+
end
|
|
166
|
+
@delegate_dc_obj
|
|
167
|
+
end
|
|
168
|
+
def __setobj__(obj) # :nodoc:
|
|
169
|
+
__raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
|
|
170
|
+
@delegate_dc_obj = obj
|
|
171
|
+
end
|
|
172
|
+
methods.each do |method|
|
|
173
|
+
define_method(method, Delegator.delegating_block(method))
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
klass.define_singleton_method :public_instance_methods do |all=true|
|
|
177
|
+
super(all) - superclass.protected_instance_methods
|
|
178
|
+
end
|
|
179
|
+
klass.define_singleton_method :protected_instance_methods do |all=true|
|
|
180
|
+
super(all) | superclass.protected_instance_methods
|
|
181
|
+
end
|
|
182
|
+
return klass
|
|
183
|
+
end
|
data/stubs/1.8/etc.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class Etc
|
|
2
|
+
|
|
3
|
+
Group = Struct.new(:name, :passwd, :gid, :mem)
|
|
4
|
+
Passwd = Struct.new(:name, :passwd, :uid, :gid, :dir, :shell)
|
|
5
|
+
|
|
6
|
+
@group = Group.new("foo", "bar", 1, ["foo", "bar"])
|
|
7
|
+
@passwd = Passwd.new("foo", "bar", 1, 1, "foo", "bar")
|
|
8
|
+
|
|
9
|
+
def endgrent(); end
|
|
10
|
+
|
|
11
|
+
def endpwent(); end
|
|
12
|
+
|
|
13
|
+
def getgrent(); return @group; end
|
|
14
|
+
|
|
15
|
+
def getgrgid(group_id); return @group; end
|
|
16
|
+
|
|
17
|
+
def getgrnam(name); return @group; end
|
|
18
|
+
|
|
19
|
+
def getlogin(); return "Bob"; end
|
|
20
|
+
|
|
21
|
+
def getpwent(); return @passwd; end
|
|
22
|
+
|
|
23
|
+
def getpwnam(name); return @passwd; end
|
|
24
|
+
|
|
25
|
+
def getpwuid(uid); return @passwd; end
|
|
26
|
+
|
|
27
|
+
def group(); @group; end
|
|
28
|
+
|
|
29
|
+
def passwd(); @passwd; end
|
|
30
|
+
|
|
31
|
+
def setgrent(); end
|
|
32
|
+
|
|
33
|
+
def setpwent(); end
|
|
34
|
+
|
|
35
|
+
def sysconfdir()
|
|
36
|
+
"/usr/local/etc"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def systmpdir(); "/tmp"; end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
require_relative './etc'
|
|
2
|
+
|
|
3
|
+
module FileUtils
|
|
4
|
+
def self.private_module_function(name) #:nodoc:
|
|
5
|
+
module_function name
|
|
6
|
+
private_class_method name
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
OPT_TABLE = {}
|
|
10
|
+
|
|
11
|
+
def cd(dir, options);Dir.chdir(dir, &block);end
|
|
12
|
+
alias chdir cd
|
|
13
|
+
module_function :chdir
|
|
14
|
+
|
|
15
|
+
OPT_TABLE['cd'] =
|
|
16
|
+
OPT_TABLE['chdir'] = [:verbose]
|
|
17
|
+
|
|
18
|
+
def uptodate?(new, old_list)
|
|
19
|
+
return false unless File.exist?(new)
|
|
20
|
+
new_time = File.mtime(new)
|
|
21
|
+
old_list.each do |old|
|
|
22
|
+
if File.exist?(old)
|
|
23
|
+
return false unless new_time > File.mtime(old)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
true
|
|
27
|
+
end
|
|
28
|
+
module_function :uptodate?
|
|
29
|
+
|
|
30
|
+
def pwd();""end
|
|
31
|
+
alias getwd pwd
|
|
32
|
+
module_function :getwd
|
|
33
|
+
|
|
34
|
+
def mkdir(dir, options);[""];end
|
|
35
|
+
def mkdir_p(dir, options);[""];end
|
|
36
|
+
alias mkpath mkdir_p
|
|
37
|
+
alias makedirs mkdir_p
|
|
38
|
+
module_function :mkpath
|
|
39
|
+
module_function :makedirs
|
|
40
|
+
|
|
41
|
+
OPT_TABLE['mkdir_p'] =
|
|
42
|
+
OPT_TABLE['mkpath'] =
|
|
43
|
+
OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
|
|
44
|
+
|
|
45
|
+
def rmdir(dir, options);[""];end
|
|
46
|
+
OPT_TABLE['rmdir'] = [:parents, :noop, :verbose]
|
|
47
|
+
|
|
48
|
+
def ln(list, destdir, options);0;end
|
|
49
|
+
alias link ln
|
|
50
|
+
module_function :link
|
|
51
|
+
|
|
52
|
+
OPT_TABLE['ln'] =
|
|
53
|
+
OPT_TABLE['link'] = [:force, :noop, :verbose]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def ln_s(list, destdir, options);0;end
|
|
57
|
+
|
|
58
|
+
alias symlink ln_s
|
|
59
|
+
module_function :symlink
|
|
60
|
+
|
|
61
|
+
OPT_TABLE['ln_s'] =
|
|
62
|
+
OPT_TABLE['symlink'] = [:force, :noop, :verbose]
|
|
63
|
+
|
|
64
|
+
def ln_sf(src, dest, options);0;end
|
|
65
|
+
OPT_TABLE['ln_sf'] = [:noop, :verbose]
|
|
66
|
+
|
|
67
|
+
def cp(list, dir, options);nil;end
|
|
68
|
+
def cp_r(src, dest, options);nil;end
|
|
69
|
+
|
|
70
|
+
alias copy cp
|
|
71
|
+
module_function :copy
|
|
72
|
+
|
|
73
|
+
OPT_TABLE['cp'] =
|
|
74
|
+
OPT_TABLE['copy'] = [:preserve, :noop, :verbose]
|
|
75
|
+
|
|
76
|
+
def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
|
|
77
|
+
Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent|
|
|
78
|
+
destent = Entry_.new(dest, ent.rel, false)
|
|
79
|
+
File.unlink destent.path if remove_destination && File.file?(destent.path)
|
|
80
|
+
ent.copy destent.path
|
|
81
|
+
end, proc do |ent|
|
|
82
|
+
destent = Entry_.new(dest, ent.rel, false)
|
|
83
|
+
ent.copy_metadata destent.path if preserve
|
|
84
|
+
end)
|
|
85
|
+
end
|
|
86
|
+
module_function :copy_entry
|
|
87
|
+
|
|
88
|
+
def copy_file(src, dest, preserve = false, dereference = true)
|
|
89
|
+
ent = Entry_.new(src, nil, dereference)
|
|
90
|
+
ent.copy_file dest
|
|
91
|
+
ent.copy_metadata dest if preserve
|
|
92
|
+
end
|
|
93
|
+
module_function :copy_file
|
|
94
|
+
|
|
95
|
+
def copy_stream(src, dest)
|
|
96
|
+
IO.copy_stream(src, dest)
|
|
97
|
+
end
|
|
98
|
+
module_function :copy_stream
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def mv(src, dest, options);0;end
|
|
102
|
+
alias move mv
|
|
103
|
+
module_function :move
|
|
104
|
+
|
|
105
|
+
OPT_TABLE['mv'] =
|
|
106
|
+
OPT_TABLE['move'] = [:force, :noop, :verbose, :secure]
|
|
107
|
+
|
|
108
|
+
def rename_cannot_overwrite_file? #:nodoc:
|
|
109
|
+
/cygwin|mswin|mingw|bccwin|emx/ =~ RUBY_PLATFORM
|
|
110
|
+
end
|
|
111
|
+
private_module_function :rename_cannot_overwrite_file?
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def rm(list, options);[""];end
|
|
115
|
+
def rm_r(list, options);[""];end
|
|
116
|
+
def rm_rf(list, options);[""];end
|
|
117
|
+
|
|
118
|
+
alias remove rm
|
|
119
|
+
module_function :remove
|
|
120
|
+
|
|
121
|
+
OPT_TABLE['rm'] =
|
|
122
|
+
OPT_TABLE['remove'] = [:force, :noop, :verbose]
|
|
123
|
+
|
|
124
|
+
alias safe_unlink rm_f
|
|
125
|
+
module_function :safe_unlink
|
|
126
|
+
|
|
127
|
+
OPT_TABLE['rm_f'] =
|
|
128
|
+
OPT_TABLE['safe_unlink'] = [:noop, :verbose]
|
|
129
|
+
|
|
130
|
+
alias rmtree rm_rf
|
|
131
|
+
module_function :rmtree
|
|
132
|
+
|
|
133
|
+
OPT_TABLE['rm_rf'] =
|
|
134
|
+
OPT_TABLE['rmtree'] = [:noop, :verbose, :secure]
|
|
135
|
+
|
|
136
|
+
def remove_entry_secure(path, force = false);[""];end
|
|
137
|
+
|
|
138
|
+
def remove_entry(path, force = false)
|
|
139
|
+
Entry_.new(path).postorder_traverse do |ent|
|
|
140
|
+
begin
|
|
141
|
+
ent.remove
|
|
142
|
+
rescue
|
|
143
|
+
raise unless force
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
rescue
|
|
147
|
+
raise unless force
|
|
148
|
+
end
|
|
149
|
+
module_function :remove_entry
|
|
150
|
+
|
|
151
|
+
def remove_file(path, force = false)
|
|
152
|
+
Entry_.new(path).remove_file
|
|
153
|
+
rescue
|
|
154
|
+
raise unless force
|
|
155
|
+
end
|
|
156
|
+
module_function :remove_file
|
|
157
|
+
|
|
158
|
+
def remove_dir(path, force = false)
|
|
159
|
+
remove_entry path, force # FIXME?? check if it is a directory
|
|
160
|
+
end
|
|
161
|
+
module_function :remove_dir
|
|
162
|
+
|
|
163
|
+
def install(src, dest, options = {});nil;end
|
|
164
|
+
|
|
165
|
+
def compare_file(a, b)
|
|
166
|
+
return false unless File.size(a) == File.size(b)
|
|
167
|
+
File.open(a, 'rb') {|fa|
|
|
168
|
+
File.open(b, 'rb') {|fb|
|
|
169
|
+
return compare_stream(fa, fb)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
end
|
|
173
|
+
module_function :compare_file
|
|
174
|
+
|
|
175
|
+
alias identical? compare_file
|
|
176
|
+
alias cmp compare_file
|
|
177
|
+
module_function :identical?
|
|
178
|
+
module_function :cmp
|
|
179
|
+
|
|
180
|
+
def compare_stream(a, b)
|
|
181
|
+
bsize = fu_stream_blksize(a, b)
|
|
182
|
+
sa = ""
|
|
183
|
+
sb = ""
|
|
184
|
+
begin
|
|
185
|
+
a.read(bsize, sa)
|
|
186
|
+
b.read(bsize, sb)
|
|
187
|
+
return true if sa.empty? && sb.empty?
|
|
188
|
+
end while sa == sb
|
|
189
|
+
false
|
|
190
|
+
end
|
|
191
|
+
module_function :compare_stream
|
|
192
|
+
|
|
193
|
+
def chmod(mode, list, options);[""];end
|
|
194
|
+
OPT_TABLE['chmod'] = [:noop, :verbose]
|
|
195
|
+
|
|
196
|
+
def chmod_R(mode, list, options);[""];end
|
|
197
|
+
OPT_TABLE['chmod_R'] = [:noop, :verbose, :force]
|
|
198
|
+
|
|
199
|
+
def chown(user, group, list, options);[""];end
|
|
200
|
+
OPT_TABLE['chown'] = [:noop, :verbose]
|
|
201
|
+
|
|
202
|
+
def chown_R(user, group, list, options);[""];end
|
|
203
|
+
OPT_TABLE['chown_R'] = [:noop, :verbose, :force]
|
|
204
|
+
|
|
205
|
+
def touch(list, options);[""];end
|
|
206
|
+
OPT_TABLE['touch'] = [:noop, :verbose, :mtime, :nocreate]
|
|
207
|
+
|
|
208
|
+
module_function :pwd
|
|
209
|
+
module_function :getwd
|
|
210
|
+
module_function :cd
|
|
211
|
+
module_function :mkdir
|
|
212
|
+
module_function :mkdir_p
|
|
213
|
+
module_function :rmdir
|
|
214
|
+
module_function :ln
|
|
215
|
+
module_function :ln_s
|
|
216
|
+
module_function :ln_sf
|
|
217
|
+
module_function :cp
|
|
218
|
+
module_function :cp_r
|
|
219
|
+
module_function :mv
|
|
220
|
+
module_function :rm
|
|
221
|
+
module_function :remove
|
|
222
|
+
module_function :rm_f
|
|
223
|
+
module_function :rm_r
|
|
224
|
+
module_function :rm_rf
|
|
225
|
+
module_function :chmod
|
|
226
|
+
module_function :chmod_R
|
|
227
|
+
module_function :chown
|
|
228
|
+
module_function :chown_R
|
|
229
|
+
module_function :touch
|
|
230
|
+
|
|
231
|
+
def remove_tailing_slash(dir)
|
|
232
|
+
dir == '/' ? dir : dir.chomp(?/)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
private_module_function :remove_tailing_slash
|
|
236
|
+
|
|
237
|
+
def fu_mkdir(path, mode) #:nodoc:
|
|
238
|
+
path = remove_tailing_slash(path)
|
|
239
|
+
if mode
|
|
240
|
+
Dir.mkdir path, mode
|
|
241
|
+
File.chmod mode, path
|
|
242
|
+
else
|
|
243
|
+
Dir.mkdir path
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
private_module_function :fu_mkdir
|
|
248
|
+
|
|
249
|
+
def user_mask(target);1;end
|
|
250
|
+
private_module_function :user_mask
|
|
251
|
+
|
|
252
|
+
def apply_mask(mode, user_mask, op, mode_mask);1;end
|
|
253
|
+
private_module_function :apply_mask
|
|
254
|
+
|
|
255
|
+
def symbolic_modes_to_i(mode_sym, path);1;end
|
|
256
|
+
private_module_function :symbolic_modes_to_i
|
|
257
|
+
|
|
258
|
+
def fu_mode(mode, path);1;end
|
|
259
|
+
private_module_function :fu_mode
|
|
260
|
+
|
|
261
|
+
def mode_to_s(mode);"1";end
|
|
262
|
+
private_module_function :mode_to_s
|
|
263
|
+
|
|
264
|
+
def fu_get_uid(user);1;end
|
|
265
|
+
private_module_function :fu_get_uid
|
|
266
|
+
|
|
267
|
+
def fu_get_gid(group);1;end
|
|
268
|
+
private_module_function :fu_get_gid
|
|
269
|
+
|
|
270
|
+
def fu_list(arg)
|
|
271
|
+
[arg].flatten.map {|path| File.path(path) }
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
private_module_function :fu_list
|
|
275
|
+
|
|
276
|
+
def fu_each_src_dest(src, dest) #:nodoc:
|
|
277
|
+
fu_each_src_dest0(src, dest) do |s, d|
|
|
278
|
+
raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d)
|
|
279
|
+
yield s, d, File.stat(s)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
private_module_function :fu_each_src_dest
|
|
283
|
+
|
|
284
|
+
def fu_each_src_dest0(src, dest) #:nodoc:
|
|
285
|
+
if tmp = Array.try_convert(src)
|
|
286
|
+
tmp.each do |s|
|
|
287
|
+
s = File.path(s)
|
|
288
|
+
yield s, File.join(dest, File.basename(s))
|
|
289
|
+
end
|
|
290
|
+
else
|
|
291
|
+
src = File.path(src)
|
|
292
|
+
if File.directory?(dest)
|
|
293
|
+
yield src, File.join(dest, File.basename(src))
|
|
294
|
+
else
|
|
295
|
+
yield src, File.path(dest)
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
private_module_function :fu_each_src_dest0
|
|
300
|
+
|
|
301
|
+
def fu_check_options(options, optdecl) #:nodoc:
|
|
302
|
+
h = options.dup
|
|
303
|
+
optdecl.each do |opt|
|
|
304
|
+
h.delete opt
|
|
305
|
+
end
|
|
306
|
+
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
|
|
307
|
+
end
|
|
308
|
+
private_module_function :fu_check_options
|
|
309
|
+
|
|
310
|
+
def fu_have_symlink?
|
|
311
|
+
File.symlink nil, nil
|
|
312
|
+
rescue NotImplementedError
|
|
313
|
+
return false
|
|
314
|
+
rescue TypeError
|
|
315
|
+
return true
|
|
316
|
+
end
|
|
317
|
+
private_module_function :fu_have_symlink?
|
|
318
|
+
|
|
319
|
+
def fu_stat_identical_entry?(a, b)
|
|
320
|
+
a.dev == b.dev and a.ino == b.ino
|
|
321
|
+
end
|
|
322
|
+
private_module_function :fu_stat_identical_entry?
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def fu_update_option(args, new)
|
|
326
|
+
if tmp = Hash.try_convert(args.last)
|
|
327
|
+
args[-1] = tmp.dup.update(new)
|
|
328
|
+
else
|
|
329
|
+
args.push new
|
|
330
|
+
end
|
|
331
|
+
args
|
|
332
|
+
end
|
|
333
|
+
private_module_function :fu_update_option
|
|
334
|
+
|
|
335
|
+
@fileutils_output = $stderr
|
|
336
|
+
@fileutils_label = ''
|
|
337
|
+
|
|
338
|
+
def fu_output_message(msg) #:nodoc:
|
|
339
|
+
@fileutils_output ||= $stderr
|
|
340
|
+
@fileutils_label ||= ''
|
|
341
|
+
@fileutils_output.puts @fileutils_label + msg
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
private_module_function :fu_output_message
|
|
345
|
+
|
|
346
|
+
module StreamUtils_
|
|
347
|
+
private
|
|
348
|
+
|
|
349
|
+
def fu_windows?
|
|
350
|
+
/mswin|mingw|bccwin|emx/ =~ RUBY_PLATFORM
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
|
|
354
|
+
IO.copy_stream(src, dest)
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def fu_stream_blksize(*streams)
|
|
358
|
+
streams.each do |s|
|
|
359
|
+
next unless s.respond_to?(:stat)
|
|
360
|
+
size = fu_blksize(s.stat)
|
|
361
|
+
return size if size
|
|
362
|
+
end
|
|
363
|
+
fu_default_blksize()
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
def fu_blksize(st)
|
|
367
|
+
s = st.blksize
|
|
368
|
+
return nil unless s
|
|
369
|
+
return nil if s == 0
|
|
370
|
+
s
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def fu_default_blksize
|
|
374
|
+
1024
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
class Entry_ #:nodoc: internal use only
|
|
379
|
+
include StreamUtils_
|
|
380
|
+
|
|
381
|
+
def initialize(a, b = nil, deref = false)
|
|
382
|
+
@prefix = @rel = @path = nil
|
|
383
|
+
if b
|
|
384
|
+
@prefix = a
|
|
385
|
+
@rel = b
|
|
386
|
+
else
|
|
387
|
+
@path = a
|
|
388
|
+
end
|
|
389
|
+
@deref = deref
|
|
390
|
+
@stat = nil
|
|
391
|
+
@lstat = nil
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
def inspect
|
|
395
|
+
"\#<#{self.class} #{path()}>"
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def path
|
|
399
|
+
if @path
|
|
400
|
+
File.path(@path)
|
|
401
|
+
else
|
|
402
|
+
join(@prefix, @rel)
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
def prefix
|
|
407
|
+
@prefix || @path
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def rel
|
|
411
|
+
@rel
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
def dereference?
|
|
415
|
+
@deref
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
def exist?
|
|
419
|
+
lstat! ? true : false
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def file?
|
|
423
|
+
s = lstat!
|
|
424
|
+
s and s.file?
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
def directory?
|
|
428
|
+
s = lstat!
|
|
429
|
+
s and s.directory?
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
def symlink?
|
|
433
|
+
s = lstat!
|
|
434
|
+
s and s.symlink?
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
def chardev?
|
|
438
|
+
s = lstat!
|
|
439
|
+
s and s.chardev?
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
def blockdev?
|
|
443
|
+
s = lstat!
|
|
444
|
+
s and s.blockdev?
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
def socket?
|
|
448
|
+
s = lstat!
|
|
449
|
+
s and s.socket?
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
def pipe?
|
|
453
|
+
s = lstat!
|
|
454
|
+
s and s.pipe?
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
S_IF_DOOR = 0xD000
|
|
458
|
+
|
|
459
|
+
def door?
|
|
460
|
+
s = lstat!
|
|
461
|
+
s and (s.mode & 0xF000 == S_IF_DOOR)
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
def entries
|
|
465
|
+
opts = {}
|
|
466
|
+
opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
|
|
467
|
+
Dir.entries(path(), opts)\
|
|
468
|
+
.reject {|n| n == '.' or n == '..' }\
|
|
469
|
+
.map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
def stat
|
|
473
|
+
return @stat if @stat
|
|
474
|
+
if lstat() and lstat().symlink?
|
|
475
|
+
@stat = File.stat(path())
|
|
476
|
+
else
|
|
477
|
+
@stat = lstat()
|
|
478
|
+
end
|
|
479
|
+
@stat
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
def stat!
|
|
483
|
+
return @stat if @stat
|
|
484
|
+
if lstat! and lstat!.symlink?
|
|
485
|
+
@stat = File.stat(path())
|
|
486
|
+
else
|
|
487
|
+
@stat = lstat!
|
|
488
|
+
end
|
|
489
|
+
@stat
|
|
490
|
+
rescue SystemCallError
|
|
491
|
+
nil
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
def lstat
|
|
495
|
+
if dereference?
|
|
496
|
+
@lstat ||= File.stat(path())
|
|
497
|
+
else
|
|
498
|
+
@lstat ||= File.lstat(path())
|
|
499
|
+
end
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
def lstat!
|
|
503
|
+
lstat()
|
|
504
|
+
rescue SystemCallError
|
|
505
|
+
nil
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
def chmod(mode)
|
|
509
|
+
if symlink?
|
|
510
|
+
File.lchmod mode, path() if have_lchmod?
|
|
511
|
+
else
|
|
512
|
+
File.chmod mode, path()
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
def chown(uid, gid)
|
|
517
|
+
if symlink?
|
|
518
|
+
File.lchown uid, gid, path() if have_lchown?
|
|
519
|
+
else
|
|
520
|
+
File.chown uid, gid, path()
|
|
521
|
+
end
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
def copy(dest)
|
|
525
|
+
case
|
|
526
|
+
when file?
|
|
527
|
+
copy_file dest
|
|
528
|
+
when directory?
|
|
529
|
+
if !File.exist?(dest) and descendant_diretory?(dest, path)
|
|
530
|
+
raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest]
|
|
531
|
+
end
|
|
532
|
+
begin
|
|
533
|
+
Dir.mkdir dest
|
|
534
|
+
rescue
|
|
535
|
+
raise unless File.directory?(dest)
|
|
536
|
+
end
|
|
537
|
+
when symlink?
|
|
538
|
+
File.symlink File.readlink(path()), dest
|
|
539
|
+
when chardev?
|
|
540
|
+
raise "cannot handle device file" unless File.respond_to?(:mknod)
|
|
541
|
+
mknod dest, ?c, 0666, lstat().rdev
|
|
542
|
+
when blockdev?
|
|
543
|
+
raise "cannot handle device file" unless File.respond_to?(:mknod)
|
|
544
|
+
mknod dest, ?b, 0666, lstat().rdev
|
|
545
|
+
when socket?
|
|
546
|
+
raise "cannot handle socket" unless File.respond_to?(:mknod)
|
|
547
|
+
mknod dest, nil, lstat().mode, 0
|
|
548
|
+
when pipe?
|
|
549
|
+
raise "cannot handle FIFO" unless File.respond_to?(:mkfifo)
|
|
550
|
+
mkfifo dest, 0666
|
|
551
|
+
when door?
|
|
552
|
+
raise "cannot handle door: #{path()}"
|
|
553
|
+
else
|
|
554
|
+
raise "unknown file type: #{path()}"
|
|
555
|
+
end
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
def copy_file(dest)
|
|
559
|
+
File.open(path()) do |s|
|
|
560
|
+
File.open(dest, 'wb', s.stat.mode) do |f|
|
|
561
|
+
IO.copy_stream(s, f)
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
def copy_metadata(path)
|
|
567
|
+
st = lstat()
|
|
568
|
+
if !st.symlink?
|
|
569
|
+
File.utime st.atime, st.mtime, path
|
|
570
|
+
end
|
|
571
|
+
begin
|
|
572
|
+
if st.symlink?
|
|
573
|
+
begin
|
|
574
|
+
File.lchown st.uid, st.gid, path
|
|
575
|
+
rescue NotImplementedError
|
|
576
|
+
end
|
|
577
|
+
else
|
|
578
|
+
File.chown st.uid, st.gid, path
|
|
579
|
+
end
|
|
580
|
+
rescue Errno::EPERM
|
|
581
|
+
# clear setuid/setgid
|
|
582
|
+
if st.symlink?
|
|
583
|
+
begin
|
|
584
|
+
File.lchmod st.mode & 01777, path
|
|
585
|
+
rescue NotImplementedError
|
|
586
|
+
end
|
|
587
|
+
else
|
|
588
|
+
File.chmod st.mode & 01777, path
|
|
589
|
+
end
|
|
590
|
+
else
|
|
591
|
+
if st.symlink?
|
|
592
|
+
begin
|
|
593
|
+
File.lchmod st.mode, path
|
|
594
|
+
rescue NotImplementedError
|
|
595
|
+
end
|
|
596
|
+
else
|
|
597
|
+
File.chmod st.mode, path
|
|
598
|
+
end
|
|
599
|
+
end
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
def remove
|
|
603
|
+
if directory?
|
|
604
|
+
remove_dir1
|
|
605
|
+
else
|
|
606
|
+
remove_file
|
|
607
|
+
end
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
def remove_dir1
|
|
611
|
+
platform_support {
|
|
612
|
+
Dir.rmdir path().chomp(?/)
|
|
613
|
+
}
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
def remove_file
|
|
617
|
+
platform_support {
|
|
618
|
+
File.unlink path
|
|
619
|
+
}
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
def platform_support
|
|
623
|
+
return yield unless fu_windows?
|
|
624
|
+
first_time_p = true
|
|
625
|
+
begin
|
|
626
|
+
yield
|
|
627
|
+
rescue Errno::ENOENT
|
|
628
|
+
raise
|
|
629
|
+
rescue => err
|
|
630
|
+
if first_time_p
|
|
631
|
+
first_time_p = false
|
|
632
|
+
begin
|
|
633
|
+
File.chmod 0700, path() # Windows does not have symlink
|
|
634
|
+
retry
|
|
635
|
+
rescue SystemCallError
|
|
636
|
+
end
|
|
637
|
+
end
|
|
638
|
+
raise err
|
|
639
|
+
end
|
|
640
|
+
end
|
|
641
|
+
|
|
642
|
+
def preorder_traverse
|
|
643
|
+
stack = [self]
|
|
644
|
+
while ent = stack.pop
|
|
645
|
+
yield ent
|
|
646
|
+
stack.concat ent.entries.reverse if ent.directory?
|
|
647
|
+
end
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
alias traverse preorder_traverse
|
|
651
|
+
|
|
652
|
+
def postorder_traverse
|
|
653
|
+
if directory?
|
|
654
|
+
entries().each do |ent|
|
|
655
|
+
ent.postorder_traverse do |e|
|
|
656
|
+
yield e
|
|
657
|
+
end
|
|
658
|
+
end
|
|
659
|
+
end
|
|
660
|
+
yield self
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
def wrap_traverse(pre, post)
|
|
664
|
+
pre.call self
|
|
665
|
+
if directory?
|
|
666
|
+
entries.each do |ent|
|
|
667
|
+
ent.wrap_traverse pre, post
|
|
668
|
+
end
|
|
669
|
+
end
|
|
670
|
+
post.call self
|
|
671
|
+
end
|
|
672
|
+
|
|
673
|
+
private
|
|
674
|
+
|
|
675
|
+
$fileutils_rb_have_lchmod = nil
|
|
676
|
+
|
|
677
|
+
def have_lchmod?
|
|
678
|
+
# This is not MT-safe, but it does not matter.
|
|
679
|
+
if $fileutils_rb_have_lchmod == nil
|
|
680
|
+
$fileutils_rb_have_lchmod = check_have_lchmod?
|
|
681
|
+
end
|
|
682
|
+
$fileutils_rb_have_lchmod
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
def check_have_lchmod?
|
|
686
|
+
return false unless File.respond_to?(:lchmod)
|
|
687
|
+
File.lchmod 0
|
|
688
|
+
return true
|
|
689
|
+
rescue NotImplementedError
|
|
690
|
+
return false
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
$fileutils_rb_have_lchown = nil
|
|
694
|
+
|
|
695
|
+
def have_lchown?
|
|
696
|
+
# This is not MT-safe, but it does not matter.
|
|
697
|
+
if $fileutils_rb_have_lchown == nil
|
|
698
|
+
$fileutils_rb_have_lchown = check_have_lchown?
|
|
699
|
+
end
|
|
700
|
+
$fileutils_rb_have_lchown
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
def check_have_lchown?
|
|
704
|
+
return false unless File.respond_to?(:lchown)
|
|
705
|
+
File.lchown nil, nil
|
|
706
|
+
return true
|
|
707
|
+
rescue NotImplementedError
|
|
708
|
+
return false
|
|
709
|
+
end
|
|
710
|
+
|
|
711
|
+
def join(dir, base)
|
|
712
|
+
return File.path(dir) if not base or base == '.'
|
|
713
|
+
return File.path(base) if not dir or dir == '.'
|
|
714
|
+
File.join(dir, base)
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
if File::ALT_SEPARATOR
|
|
718
|
+
DIRECTORY_TERM = "(?=[/#{Regexp.quote(File::ALT_SEPARATOR)}]|\\z)".freeze
|
|
719
|
+
else
|
|
720
|
+
DIRECTORY_TERM = "(?=/|\\z)".freeze
|
|
721
|
+
end
|
|
722
|
+
SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : ""
|
|
723
|
+
|
|
724
|
+
def descendant_diretory?(descendant, ascendant)
|
|
725
|
+
/\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant)
|
|
726
|
+
end
|
|
727
|
+
end # class Entry_
|
|
728
|
+
|
|
729
|
+
def fu_same?(a, b) #:nodoc:
|
|
730
|
+
File.identical?(a, b)
|
|
731
|
+
end
|
|
732
|
+
private_module_function :fu_same?
|
|
733
|
+
|
|
734
|
+
@fileutils_output = $stderr
|
|
735
|
+
@fileutils_label = ''
|
|
736
|
+
|
|
737
|
+
def FileUtils.commands
|
|
738
|
+
OPT_TABLE.keys
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
def FileUtils.options
|
|
742
|
+
OPT_TABLE.values.flatten.uniq.map {|sym| sym.to_s }
|
|
743
|
+
end
|
|
744
|
+
|
|
745
|
+
def FileUtils.have_option?(mid, opt)
|
|
746
|
+
li = OPT_TABLE[mid.to_s] or raise ArgumentError, "no such method: #{mid}"
|
|
747
|
+
li.include?(opt)
|
|
748
|
+
end
|
|
749
|
+
|
|
750
|
+
def FileUtils.options_of(mid)
|
|
751
|
+
OPT_TABLE[mid.to_s].map {|sym| sym.to_s }
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
def FileUtils.collect_method(opt)
|
|
755
|
+
OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) }
|
|
756
|
+
end
|
|
757
|
+
|
|
758
|
+
LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern)
|
|
759
|
+
module LowMethods
|
|
760
|
+
module_eval("private\n" + ::FileUtils::LOW_METHODS.map {|name| "def #{name}(*)end"}.join("\n"),
|
|
761
|
+
__FILE__, __LINE__)
|
|
762
|
+
end
|
|
763
|
+
|
|
764
|
+
METHODS = singleton_methods() - [:private_module_function,
|
|
765
|
+
:commands, :options, :have_option?, :options_of, :collect_method]
|
|
766
|
+
|
|
767
|
+
module Verbose
|
|
768
|
+
include FileUtils
|
|
769
|
+
@fileutils_output = $stderr
|
|
770
|
+
@fileutils_label = ''
|
|
771
|
+
::FileUtils.collect_method(:verbose).each do |name|
|
|
772
|
+
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
|
773
|
+
def #{name}(*args)
|
|
774
|
+
super(*fu_update_option(args, :verbose => true))
|
|
775
|
+
end
|
|
776
|
+
private :#{name}
|
|
777
|
+
EOS
|
|
778
|
+
end
|
|
779
|
+
extend self
|
|
780
|
+
class << self
|
|
781
|
+
::FileUtils::METHODS.each do |m|
|
|
782
|
+
public m
|
|
783
|
+
end
|
|
784
|
+
end
|
|
785
|
+
end
|
|
786
|
+
|
|
787
|
+
module NoWrite
|
|
788
|
+
include FileUtils
|
|
789
|
+
include LowMethods
|
|
790
|
+
@fileutils_output = $stderr
|
|
791
|
+
@fileutils_label = ''
|
|
792
|
+
::FileUtils.collect_method(:noop).each do |name|
|
|
793
|
+
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
|
794
|
+
def #{name}(*args)
|
|
795
|
+
super(*fu_update_option(args, :noop => true))
|
|
796
|
+
end
|
|
797
|
+
private :#{name}
|
|
798
|
+
EOS
|
|
799
|
+
end
|
|
800
|
+
extend self
|
|
801
|
+
class << self
|
|
802
|
+
::FileUtils::METHODS.each do |m|
|
|
803
|
+
public m
|
|
804
|
+
end
|
|
805
|
+
end
|
|
806
|
+
end
|
|
807
|
+
|
|
808
|
+
module DryRun
|
|
809
|
+
include FileUtils
|
|
810
|
+
include LowMethods
|
|
811
|
+
@fileutils_output = $stderr
|
|
812
|
+
@fileutils_label = ''
|
|
813
|
+
::FileUtils.collect_method(:noop).each do |name|
|
|
814
|
+
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
|
815
|
+
def #{name}(*args)
|
|
816
|
+
super(*fu_update_option(args, :noop => true, :verbose => true))
|
|
817
|
+
end
|
|
818
|
+
private :#{name}
|
|
819
|
+
EOS
|
|
820
|
+
end
|
|
821
|
+
extend self
|
|
822
|
+
class << self
|
|
823
|
+
::FileUtils::METHODS.each do |m|
|
|
824
|
+
public m
|
|
825
|
+
end
|
|
826
|
+
end
|
|
827
|
+
end
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
module FileUtils
|
|
832
|
+
include StreamUtils_
|
|
833
|
+
extend StreamUtils_
|
|
834
|
+
end
|