lib/fulmar/infrastructure/model/transfer/rsync_with_versions.rb in fulmar-2.0.0 vs lib/fulmar/infrastructure/model/transfer/rsync_with_versions.rb in fulmar-2.0.1

- old
+ new

@@ -22,11 +22,11 @@ rsync: { exclude: nil, exclude_file: nil, chown: nil, chmod: nil, - delete: true + delete: true }, symlinks: {}, limit_releases: 5, shared: [] } @@ -54,11 +54,14 @@ # Copy the files via rsync to the release_path on the remote machine # @return [true, false] success def transfer prepare unless @prepared - create_paths && @local_shell.run(rsync_command) && copy_temp_to_release && add_shared + fail 'Deployment failed when trying to prepare remote directories for sync.' unless create_paths + fail 'Deployment failed. Cannot sync files.' unless @local_shell.run(rsync_command) + fail 'Deployment failed when trying to move file from temporary upload dir.' unless copy_temp_to_release + fail 'Deployment failed when creating symlinks for shared folders' unless add_shared end # Publishes the current release (i.e. sets the 'current' symlink) # @return [true, false] success def publish @@ -151,11 +154,11 @@ end # Builds the rsync command # @return [String] the command def rsync_command - options = ['-rl'] + options = %w(-rl --delete-excluded) options << rsync_excludes if rsync_excludes options << "--exclude-from='#{@config[:rsync][:exclude_file]}'" if @config[:rsync][:exclude_file] options << "--chown='#{@config[:rsync][:chown]}'" if @config[:rsync][:chown] options << "--chmod='#{@config[:rsync][:chmod]}'" if @config[:rsync][:chmod] options << '--delete' if @config[:rsync][:delete] @@ -164,11 +167,11 @@ end # Copies the data from the sync temp to the actual release directory # @return [true, false] success def copy_temp_to_release - @remote_shell.run "cp -pr #{@config[:temp_dir]} #{release_dir}" + @remote_shell.run "cp -pR #{@config[:temp_dir]} #{release_dir}" end # Set the symlink to the given release or the return value of release_dir() otherwise # # @params release [String] the release folder @@ -185,27 +188,26 @@ # An entry in :shared might be "data/resources/images", so we first need to create # the directory "data/resources" in the release dir and afterwards create the link # @return [true, false] success def add_shared commands = [] # Collect all remote commands first, then execute them in one step to avoid reconnecting very often - @config[:shared].each do |dir| - commands << "mkdir -p \"#{release_dir}/#{dir}\"" + @config[:shared].each do |path| + commands << "mkdir -p \"#{release_dir}/#{File.dirname(path)}\"" - unless remote_dir_exists?("#{@config[:shared_dir]}/#{dir}") - commands << "mkdir -p \"#{@config[:shared_dir]}/#{File.dirname(dir)}\"" - commands << "cp -pr \"#{release_dir}/#{dir}\" \"#{@config[:shared_dir]}/#{File.dirname(dir)}\"" + unless remote_path_exists?("#{@config[:shared_dir]}/#{path}") + commands << "mkdir -p \"#{@config[:shared_dir]}/#{path}\"" end - commands << "rm -fr \"#{release_dir}/#{dir}\"" - commands << "mkdir -p \"#{release_dir}/#{File.dirname(dir)}\"" - commands << "ln -s \"#{@config[:remote_path]}/#{@config[:shared_dir]}/#{dir}\" \"#{release_dir}/#{dir}\"" + commands << "rm -fr \"#{release_dir}/#{path}\"" + commands << "mkdir -p \"#{release_dir}/#{File.dirname(path)}\"" + commands << "ln -s \"#{@config[:remote_path]}/#{@config[:shared_dir]}/#{path}\" \"#{release_dir}/#{path}\"" end @remote_shell.run commands if commands.length > 0 end - def remote_dir_exists?(dir) - @remote_shell.run "test -d \"#{dir}\"" + def remote_path_exists?(dir) + @remote_shell.run "test -e \"#{dir}\"" end end end end end