aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-27 07:55:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-27 07:55:17 +0000
commitfa68e03dbbd82b81e89099daeb0c70020c6be404 (patch)
tree737f2309dda93c8a3e895b01feb25ba0e9c349e9 /lib
parent7d2edb376d8d34630b3a1902f0919a1e56463e2d (diff)
downloadruby-fa68e03dbbd82b81e89099daeb0c70020c6be404.tar.gz
FileUtils#install: owner/group options
* lib/fileutils.rb (FileUtils#install): add owner and group options. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/fileutils.rb16
-rw-r--r--lib/un.rb6
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index a7fca26dbb..d5bda95b58 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -754,9 +754,20 @@ module FileUtils
# FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
# FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
#
- def install(src, dest, mode: nil, preserve: nil, noop: nil, verbose: nil)
- fu_output_message "install -c#{preserve && ' -p'}#{mode ? (' -m 0%o' % mode) : ''} #{[src,dest].flatten.join ' '}" if verbose
+ def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil,
+ noop: nil, verbose: nil)
+ if verbose
+ msg = +"install -c"
+ msg << ' -p' if preserve
+ msg << ' -m 0%o' % mode if mode
+ msg << " -o #{owner}" if owner
+ msg << " -g #{group}" if group
+ msg << ' ' << [src,dest].flatten.join(' ')
+ fu_output_message msg
+ end
return if noop
+ uid = fu_get_uid(owner)
+ gid = fu_get_gid(group)
fu_each_src_dest(src, dest) do |s, d|
st = File.stat(s)
unless File.exist?(d) and compare_file(s, d)
@@ -764,6 +775,7 @@ module FileUtils
copy_file s, d
File.utime st.atime, st.mtime, d if preserve
File.chmod mode, d if mode
+ File.chown uid, gid, d if uid or gid
end
end
end
diff --git a/lib/un.rb b/lib/un.rb
index 9c1ce624a5..54abd74060 100644
--- a/lib/un.rb
+++ b/lib/un.rb
@@ -189,13 +189,17 @@ end
# -p apply access/modification times of SOURCE files to
# corresponding destination files
# -m set permission mode (as in chmod), instead of 0755
+# -o set owner user id, instead of the current owner
+# -g set owner group id, instead of the current group
# -v verbose
#
def install
- setup("pm:") do |argv, options|
+ setup("pm:o:g:") do |argv, options|
options[:mode] = (mode = options.delete :m) ? mode.oct : 0755
options[:preserve] = true if options.delete :p
+ (owner = options.delete :o) and options[:owner] = owner
+ (group = options.delete :g) and options[:group] = group
dest = argv.pop
argv = argv[0] if argv.size == 1
FileUtils.install argv, dest, options