Skip to content

Commit

Permalink
use cp -a ... to copy also the ACLs
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Aug 28, 2015
1 parent ac17dfd commit afb2a25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/lib/registration/sw_mgmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

require "tmpdir"
require "fileutils"
require "shellwords"

require "registration/exceptions"
require "registration/helpers"
Expand Down Expand Up @@ -332,9 +333,11 @@ def self.copy_old_credentials_file(file)
new_file = SUSE::Connect::Credentials::GLOBAL_CREDENTIALS_FILE
log.info "Copying the old credentials from previous installation"
log.info "Copying #{file} to #{new_file}"
# preserve the original file permissions (equivalent to "cp -p")
# (SMT uses different permissions than the defaults, make sure it works after upgrade)
::FileUtils.cp(file, new_file, preserve: true)

# SMT uses extra ACL permissions, make sure they are kept in the copied file,
# (use "cp -a ", ::FileUtils.cp(..., preserve: true) cannot be used as it preserves only
# the traditional Unix file permissions, the extended ACLs are NOT copied!)
`cp -a #{Shellwords.escape(file)} #{Shellwords.escape(new_file)}`

credentials = SUSE::Connect::Credentials.read(new_file)
# note: SUSE::Connect::Credentials override #to_s, the password is filtered out
Expand Down
8 changes: 4 additions & 4 deletions test/sw_mgmt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@
expect(File).to receive(:exist?).with(File.join(root_dir, target_dir, "SCCcredentials"))
.and_return(false)

expect(FileUtils).to receive(:cp).with(File.join(root_dir, target_dir, "NCCcredentials"),
File.join(target_dir, "SCCcredentials"), preserve: true)
expect(subject).to receive(:`).with("cp -a " + File.join(root_dir, target_dir, "NCCcredentials") +
" " + File.join(target_dir, "SCCcredentials"))
expect(SUSE::Connect::Credentials).to receive(:read)

expect { subject.copy_old_credentials(root_dir) }.to_not raise_error
Expand All @@ -191,8 +191,8 @@
expect(File).to receive(:exist?).with(File.join(root_dir, target_dir, "SCCcredentials"))
.and_return(true)

expect(FileUtils).to receive(:cp).with(File.join(root_dir, target_dir, "SCCcredentials"),
File.join(target_dir, "SCCcredentials"), preserve: true)
expect(subject).to receive(:`).with("cp -a " + File.join(root_dir, target_dir, "SCCcredentials") +
" " + File.join(target_dir, "SCCcredentials"))
expect(SUSE::Connect::Credentials).to receive(:read)

expect { subject.copy_old_credentials(root_dir) }.to_not raise_error
Expand Down

0 comments on commit afb2a25

Please sign in to comment.