def copy_file(self): self.mkdir_basepath() src = self.src_path dest = self.dest_path if self.dest_isFile(): unix_out('cp %s %s.saved' % (dest, dest)) unix_out('umask 077') unix_out('cp %s %s' % (src, dest)) if not synctool_lib.DRY_RUN: old_umask = os.umask(077) if synctool_param.BACKUP_COPIES: if self.dest_isFile(): verbose(' saving %s as %s.saved' % (dest, dest)) try: shutil.copy2(dest, '%s.saved' % dest) except: stderr('failed to save %s as %s.saved' % (dest, dest)) verbose(' cp %s %s' % (src, dest)) try: shutil.copy2(src, dest) # copy file and stats except: stderr('failed to copy %s to %s' % (self.print_src(), dest)) os.umask(old_umask) else: if self.dest_isFile() and synctool_param.BACKUP_COPIES: verbose(' saving %s as %s.saved' % (dest, dest)) verbose(dryrun_msg(' cp %s %s' % (src, dest)))
def erase_saved(self): dest = self.dest_path stat_saved_path = synctool_stat.SyncStat('%s.saved' % dest) if synctool_lib.ERASE_SAVED and stat_saved_path.exists() and not stat_saved_path.isDir(): terse(synctool_lib.TERSE_DELETE, '%s.saved' % dest) unix_out('rm %s.saved' % dest) if synctool_lib.DRY_RUN: stdout(dryrun_msg('erase %s.saved' % dest, 'erase')) else: stdout('erase %s.saved' % dest) verbose(' os.unlink(%s.saved)' % dest) try: os.unlink('%s.saved' % dest) except OSError, reason: stderr('failed to delete %s : %s' % (dest, reason))
stderr('failed to save %s as %s.saved : %s' % (newpath, newpath, reason)) terse(synctool_lib.TERSE_FAIL, 'save %s.saved' % newpath) old_umask = os.umask(umask_mode) verbose(' os.symlink(%s, %s)' % (oldpath, newpath)) try: os.symlink(oldpath, newpath) except OSError, reason: stderr('failed to create symlink %s -> %s : %s' % (newpath, oldpath, reason)) terse(synctool_lib.TERSE_FAIL, 'link %s' % newpath) os.umask(old_umask) else: verbose(dryrun_msg(' os.symlink(%s, %s)' % (oldpath, newpath))) def set_permissions(self): file = self.dest_path mode = self.src_statbuf.mode unix_out('chmod 0%o %s' % (mode & 07777, file)) if not synctool_lib.DRY_RUN: verbose(' os.chmod(%s, %04o)' % (file, mode & 07777)) try: os.chmod(file, mode & 07777) except OSError, reason: stderr('failed to chmod %04o %s : %s' % (mode & 07777, file, reason)) else:
stderr("failed to save %s as %s.saved : %s" % (newpath, newpath, reason)) terse(synctool_lib.TERSE_FAIL, "save %s.saved" % newpath) old_umask = os.umask(umask_mode) verbose(" os.symlink(%s, %s)" % (oldpath, newpath)) try: os.symlink(oldpath, newpath) except OSError, reason: stderr("failed to create symlink %s -> %s : %s" % (newpath, oldpath, reason)) terse(synctool_lib.TERSE_FAIL, "link %s" % newpath) os.umask(old_umask) else: verbose(dryrun_msg(" os.symlink(%s, %s)" % (oldpath, newpath))) def set_permissions(self): file = self.dest_path mode = self.src_statbuf.mode unix_out("chmod 0%o %s" % (mode & 07777, file)) if not synctool_lib.DRY_RUN: verbose(" os.chmod(%s, %04o)" % (file, mode & 07777)) try: os.chmod(file, mode & 07777) except OSError, reason: stderr("failed to chmod %04o %s : %s" % (mode & 07777, file, reason)) else: verbose(dryrun_msg(" os.chmod(%s, %04o)" % (file, mode & 07777)))