1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
require_relative '../../spec_helper'
describe "File.chown" do
before :each do
@fname = tmp('file_chown_test')
touch @fname
end
after :each do
rm_r @fname
end
as_superuser do
platform_is :windows do
it "does not modify the owner id of the file" do
File.chown 0, nil, @fname
File.stat(@fname).uid.should == 0
File.chown 501, nil, @fname
File.stat(@fname).uid.should == 0
end
it "does not modify the group id of the file" do
File.chown nil, 0, @fname
File.stat(@fname).gid.should == 0
File.chown nil, 501, @fname
File.stat(@fname).gid.should == 0
end
end
platform_is_not :windows do
it "changes the owner id of the file" do
File.chown 501, nil, @fname
File.stat(@fname).uid.should == 501
File.chown 0, nil, @fname
File.stat(@fname).uid.should == 0
end
it "changes the group id of the file" do
File.chown nil, 501, @fname
File.stat(@fname).gid.should == 501
File.chown nil, 0, @fname
File.stat(@fname).uid.should == 0
end
it "does not modify the owner id of the file if passed nil or -1" do
File.chown 501, nil, @fname
File.chown nil, nil, @fname
File.stat(@fname).uid.should == 501
File.chown nil, -1, @fname
File.stat(@fname).uid.should == 501
end
it "does not modify the group id of the file if passed nil or -1" do
File.chown nil, 501, @fname
File.chown nil, nil, @fname
File.stat(@fname).gid.should == 501
File.chown nil, -1, @fname
File.stat(@fname).gid.should == 501
end
end
end
it "returns the number of files processed" do
File.chown(nil, nil, @fname, @fname).should == 2
end
platform_is_not :windows do
it "raises an error for a non existent path" do
-> {
File.chown(nil, nil, "#{@fname}_not_existing")
}.should raise_error(Errno::ENOENT)
end
end
it "accepts an object that has a #to_path method" do
File.chown(nil, nil, mock_to_path(@fname)).should == 1
end
end
describe "File#chown" do
before :each do
@fname = tmp('file_chown_test')
@file = File.open(@fname, 'w')
end
after :each do
@file.close unless @file.closed?
rm_r @fname
end
as_superuser do
platform_is :windows do
it "does not modify the owner id of the file" do
@file.chown 0, nil
@file.stat.uid.should == 0
@file.chown 501, nil
@file.stat.uid.should == 0
end
it "does not modify the group id of the file" do
@file.chown nil, 0
@file.stat.gid.should == 0
@file.chown nil, 501
@file.stat.gid.should == 0
end
end
platform_is_not :windows do
it "changes the owner id of the file" do
@file.chown 501, nil
@file.stat.uid.should == 501
@file.chown 0, nil
@file.stat.uid.should == 0
end
it "changes the group id of the file" do
@file.chown nil, 501
@file.stat.gid.should == 501
@file.chown nil, 0
@file.stat.uid.should == 0
end
it "does not modify the owner id of the file if passed nil or -1" do
@file.chown 501, nil
@file.chown nil, nil
@file.stat.uid.should == 501
@file.chown nil, -1
@file.stat.uid.should == 501
end
it "does not modify the group id of the file if passed nil or -1" do
@file.chown nil, 501
@file.chown nil, nil
@file.stat.gid.should == 501
@file.chown nil, -1
@file.stat.gid.should == 501
end
end
end
it "returns 0" do
@file.chown(nil, nil).should == 0
end
end
|