Skip to content

Commit

Permalink
Make send_file aware of user option
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Dec 27, 2018
1 parent 425b9f7 commit 72bb9a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/itamae/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,20 @@ def receive_file(src, dst = nil)
@backend.receive_file(src, dst)
end

def send_file(src, dst)
def send_file(src, dst, user: nil)
Itamae.logger.debug "Sending a file from '#{src}' to '#{dst}'..."
unless ::File.exist?(src)
raise SourceNotExistError, "The file '#{src}' doesn't exist."
end
unless ::File.file?(src)
raise SourceNotExistError, "'#{src}' is not a file."
end
@backend.send_file(src, dst)

if self.instance_of?(Backend::Local)
run_command(get_command(:copy_file, src, dst), user: user)
else
@backend.send_file(src, dst)
end
end

def send_directory(src, dst)
Expand Down
4 changes: 2 additions & 2 deletions lib/itamae/resource/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ def send_tempfile

if backend.is_a?(Itamae::Backend::Docker)
run_command(["mkdir", @temppath])
backend.send_file(src, @temppath)
backend.send_file(src, @temppath, user: attributes.user)
@temppath = ::File.join(@temppath, ::File.basename(src))
else
run_command(["touch", @temppath])
run_specinfra(:change_file_mode, @temppath, '0600')
backend.send_file(src, @temppath)
backend.send_file(src, @temppath, user: attributes.user)
end

run_specinfra(:change_file_mode, @temppath, '0600')
Expand Down

0 comments on commit 72bb9a1

Please sign in to comment.