Method: Etch::Client#make_backup

Defined in:
lib/etch/client.rb

#make_backup(file) ⇒ Object



1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
# File 'lib/etch/client.rb', line 1941

def make_backup(file)
  backup = nil
  filebase = File.basename(file)
  filedir = File.dirname(file)
  if !@dryrun
    backup = tempdir(file)
  else
    # Use a fake placeholder name for use in dry run/debug messages
    backup = "#{file}.XXXX"
  end

  backuppath = File.join(backup, filebase)

  puts "Making backup:  #{file} -> #{backuppath}"
  if !@dryrun
    if File.exist?(file) || File.symlink?(file)
      recursive_copy(filedir, filebase, backup)
    else
      # If there's no file to back up then leave a marker file so
      # that restore_backup does the right thing
      File.open("#{backuppath}.NOORIG", "w") { |markerfile| }
    end
  end

  backup
end