def _restoreItem(item, cwd, as_): """ Restores the provided item to the current working directory. If the 'as' is not provided, the original file name is preserved. """ if as_: restoreAs = os.path.join(cwd, as_) else: restoreAs = os.path.join(cwd, os.path.basename(item)) if os.path.exists(restoreAs): if _confirmOverwrite(restoreAs): fn.copy(item, restoreAs) else: fn.copy(item, restoreAs)
def backupFile(backupRoot, previousBackup, file_, altRoot, writer): """ Backup a file to according to the files state. If it's new or modified, it's copied otherwise a hard link is created pointing to the file found in the previous backup. """ previousFileName = previousBackup + fn.removeAltRoot(altRoot, file_) backupFileName = backupRoot + fn.removeAltRoot(altRoot, file_) if isFileModifiedOrNew(previousFileName, file_): writer("Copying: {0}".format(file_)) fn.copy(file_, backupFileName) else: writer("Linking: {0}".format(file_)) os.link(previousFileName, backupFileName)