Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed chown and chown_R to actually set uid/gid

  • Loading branch information...
commit 12ac70804523277731d4bfa71a3b9b07dabeeb89 1 parent 61a8b17
@mmriis authored
Showing with 22 additions and 8 deletions.
  1. +5 −1 lib/fakefs/fileutils.rb
  2. +17 −7 test/fakefs_test.rb
View
6 lib/fakefs/fileutils.rb
@@ -118,7 +118,11 @@ def mv(src, dest, options={})
def chown(user, group, list, options={})
list = Array(list)
list.each do |f|
- unless File.exists?(f)
+ if File.exists?(f)
+ uid = (user.to_s.match(/[0-9]+/) ? user.to_i : Etc.getpwnam(user).uid)
+ gid = (group.to_s.match(/[0-9]+/) ? group.to_i : Etc.getgrnam(group).gid)
+ File.chown(uid, gid, f)
+ else
raise Errno::ENOENT, f
end
end
View
24 test/fakefs_test.rb
@@ -690,29 +690,39 @@ def test_can_chown_files
good = 'file.txt'
bad = 'nofile.txt'
File.open(good,'w') { |f| f.write "foo" }
+ username = Etc.getpwuid(Process.uid).name
+ groupname = Etc.getgrgid(Process.gid).name
- out = FileUtils.chown('noone', 'nogroup', good, :verbose => true)
+ out = FileUtils.chown(1337, 1338, good, :verbose => true)
assert_equal [good], out
+ assert_equal File.stat(good).uid, 1337
+ assert_equal File.stat(good).gid, 1338
assert_raises(Errno::ENOENT) do
- FileUtils.chown('noone', 'nogroup', bad, :verbose => true)
+ FileUtils.chown(username, groupname, bad, :verbose => true)
end
- assert_equal [good], FileUtils.chown('noone', 'nogroup', good)
+ assert_equal [good], FileUtils.chown(username, groupname, good)
+ assert_equal File.stat(good).uid, Process.uid
+ assert_equal File.stat(good).gid, Process.gid
assert_raises(Errno::ENOENT) do
- FileUtils.chown('noone', 'nogroup', bad)
+ FileUtils.chown(username, groupname, bad)
end
- assert_equal [good], FileUtils.chown('noone', 'nogroup', [good])
+ assert_equal [good], FileUtils.chown(username, groupname, [good])
+ assert_equal File.stat(good).uid, Process.uid
+ assert_equal File.stat(good).gid, Process.gid
assert_raises(Errno::ENOENT) do
- FileUtils.chown('noone', 'nogroup', [good, bad])
+ FileUtils.chown(username, groupname, [good, bad])
end
end
def test_can_chown_R_files
+ username = Etc.getpwuid(Process.uid).name
+ groupname = Etc.getgrgid(Process.gid).name
FileUtils.mkdir_p '/path/'
File.open('/path/foo', 'w') { |f| f.write 'foo' }
File.open('/path/foobar', 'w') { |f| f.write 'foo' }
- resp = FileUtils.chown_R('no', 'no', '/path')
+ resp = FileUtils.chown_R(username, groupname, '/path')
assert_equal ['/path'], resp
end
Please sign in to comment.
Something went wrong with that request. Please try again.