Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #415

Merged
merged 2 commits into from
Jan 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/pdk/module/update_manager.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'set'
require 'diff/lcs'
require 'diff/lcs/hunk'
require 'English'
require 'fileutils'
require 'set'

module PDK
module Module
Expand Down Expand Up @@ -86,13 +86,13 @@ def sync_changes!
files_to_write = @added_files
files_to_write += @modified_files.reject { |file| @diff_cache[file[:path]].nil? }

files_to_write.each do |file|
write_file(file[:path], file[:content])
end

@removed_files.each do |file|
unlink_file(file)
end

files_to_write.each do |file|
write_file(file[:path], file[:content])
end
end

private
Expand Down Expand Up @@ -124,6 +124,7 @@ def calculate_diffs
# @raise [PDK::CLI::ExitWithError] if the file is not writeable.
def write_file(path, content)
FileUtils.mkdir_p(File.dirname(path))
PDK.logger.debug(_("writing '%{path}'") % { path: path })
File.open(path, 'w') { |f| f.puts content }
rescue Errno::EACCES
raise PDK::CLI::ExitWithError, _("You do not have permission to write to '%{path}'") % { path: path }
Expand All @@ -139,7 +140,12 @@ def write_file(path, content)
#
# @raise [PDK::CLI::ExitWithError] if the file could not be removed.
def unlink_file(path)
FileUtils.rm(path) if File.file?(path)
if File.file?(path)
PDK.logger.debug(_("unlinking '%{path}'") % { path: path })
FileUtils.rm(path)
else
PDK.logger.debug(_("'%{path}': already gone") % { path: path })
end
rescue => e
raise PDK::CLI::ExitWithError, _("Unable to remove '%{path}': %{message}") % {
path: path,
Expand Down