def upgrade(self): msg = 'upgrading packages' verbose(dryrun_msg(msg)) # log the upgrade action ... # don't know which packages are upgraded here, sorry log(msg)
def check(self): '''check differences between src and dest, Return a FIX_xxx code ''' # src_path is under $overlay/ # dest_path is in the filesystem vnode = None if not self.dest_stat.exists(): stdout('%s does not exist' % self.dest_path) return SyncObject.FIX_CREATE src_type = self.src_stat.filetype() dest_type = self.dest_stat.filetype() if src_type != dest_type: # entry is of a different file type vnode = self.vnode_obj() stdout('%s should be a %s' % (self.dest_path, vnode.typename())) terse(synctool.lib.TERSE_WARNING, 'wrong type %s' % self.dest_path) return SyncObject.FIX_TYPE vnode = self.vnode_obj() if not vnode.compare(self.src_path, self.dest_stat): # content is different; change the entire object log('updating %s' % self.dest_path) return SyncObject.FIX_UPDATE # check ownership and permissions # rectify if needed fix_action = 0 if ((self.src_stat.uid != self.dest_stat.uid) or (self.src_stat.gid != self.dest_stat.gid)): stdout('%s should have owner %s.%s (%d.%d), ' 'but has %s.%s (%d.%d)' % (self.dest_path, self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.src_stat.uid, self.src_stat.gid, self.dest_stat.ascii_uid(), self.dest_stat.ascii_gid(), self.dest_stat.uid, self.dest_stat.gid)) terse(synctool.lib.TERSE_OWNER, '%s.%s %s' % (self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.dest_path)) fix_action = SyncObject.FIX_OWNER if self.src_stat.mode != self.dest_stat.mode: stdout('%s should have mode %04o, but has %04o' % (self.dest_path, self.src_stat.mode & 07777, self.dest_stat.mode & 07777)) terse(synctool.lib.TERSE_MODE, '%04o %s' % (self.src_stat.mode & 07777, self.dest_path)) fix_action |= SyncObject.FIX_MODE return fix_action
def fix(self, fix_action, pre_dict, post_dict): # type: (int, Dict[str, str], Dict[str, str]) -> bool '''fix differences, and run .pre/.post script if any Returns True if updated, else False ''' # most cases will have FIX_UNDEF if fix_action == SyncObject.FIX_UNDEF: return False vnode = self.vnode_obj() # Note that .post scripts are not run for owner/mode/time changes need_run = False if fix_action == SyncObject.FIX_CREATE: self.run_script(pre_dict) log('creating %s' % self.dest_path) vnode.fix() need_run = True elif fix_action == SyncObject.FIX_TYPE: self.run_script(pre_dict) log('fix type %s' % self.dest_path) vnode.fix() need_run = True elif fix_action == SyncObject.FIX_UPDATE: self.run_script(pre_dict) log('updating %s' % self.dest_path) vnode.fix() need_run = True elif fix_action == SyncObject.FIX_OWNER: log('set owner %s.%s (%d.%d) %s' % (self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.src_stat.uid, self.src_stat.gid, self.dest_path)) vnode.set_owner() if fix_action & SyncObject.FIX_MODE: log('set mode %04o %s' % (self.src_stat.mode & 07777, self.dest_path)) vnode.set_permissions() if fix_action & SyncObject.FIX_TIME: log('set time %s' % self.dest_path) # leave the atime intact vnode.stat.atime = self.dest_stat.atime vnode.set_times() # run .post script, if needed # Note: for dirs, it is run from overlay._walk_subtree() if need_run and not self.src_stat.is_dir(): self.run_script(post_dict) return True
def remove(self, pkgs): if len(pkgs) > 1: plural = 's' else: plural = '' msg = 'removing package%s: %s' % (plural, ' '.join(pkgs)) verbose(msg) log(msg)
def install(self, pkgs): if len(pkgs) > 1: plural = 's' else: plural = '' msg = 'installing package%s: %s' % (plural, ' '.join(pkgs)) verbose(msg) log(msg)
def check(self): '''check differences between src and dest, Return a FIX_xxx code ''' # src_path is under $overlay/ # dest_path is in the filesystem vnode = None if not self.dest_stat.exists(): stdout('%s does not exist' % self.dest_path) return SyncObject.FIX_CREATE src_type = self.src_stat.filetype() dest_type = self.dest_stat.filetype() if src_type != dest_type: # entry is of a different file type vnode = self.vnode_obj() stdout('%s should be a %s' % (self.dest_path, vnode.typename())) terse(synctool.lib.TERSE_WARNING, 'wrong type %s' % self.dest_path) return SyncObject.FIX_TYPE vnode = self.vnode_obj() if not vnode.compare(self.src_path, self.dest_stat): # content is different; change the entire object log('updating %s' % self.dest_path) return SyncObject.FIX_UPDATE # check ownership and permissions # rectify if needed fix_action = 0 if ((self.src_stat.uid != self.dest_stat.uid) or (self.src_stat.gid != self.dest_stat.gid)): stdout('%s should have owner %s.%s (%d.%d), ' 'but has %s.%s (%d.%d)' % (self.dest_path, self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.src_stat.uid, self.src_stat.gid, self.dest_stat.ascii_uid(), self.dest_stat.ascii_gid(), self.dest_stat.uid, self.dest_stat.gid)) terse( synctool.lib.TERSE_OWNER, '%s.%s %s' % (self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.dest_path)) fix_action = SyncObject.FIX_OWNER if self.src_stat.mode != self.dest_stat.mode: stdout('%s should have mode %04o, but has %04o' % (self.dest_path, self.src_stat.mode & 07777, self.dest_stat.mode & 07777)) terse(synctool.lib.TERSE_MODE, '%04o %s' % (self.src_stat.mode & 07777, self.dest_path)) fix_action |= SyncObject.FIX_MODE return fix_action
def remove(self, pkgs): # type: (List[str]) -> None '''remove list of packages''' if len(pkgs) > 1: plural = 's' else: plural = '' msg = 'removing package%s: %s' % (plural, ' '.join(pkgs)) verbose(msg) log(msg)
def fix(self, fix_action, pre_dict, post_dict): '''fix differences, and run .pre/.post script if any Returns True if updated, else False ''' # most cases will have FIX_UNDEF if fix_action == SyncObject.FIX_UNDEF: return False vnode = self.vnode_obj() # Note that .post scripts are not run for owner/mode changes need_run = False if fix_action == SyncObject.FIX_CREATE: self.run_script(pre_dict) log('creating %s' % self.dest_path) vnode.fix() need_run = True elif fix_action == SyncObject.FIX_TYPE: self.run_script(pre_dict) log('fix type %s' % self.dest_path) vnode.fix() need_run = True elif fix_action == SyncObject.FIX_UPDATE: self.run_script(pre_dict) log('updating %s' % self.dest_path) vnode.fix() need_run = True elif fix_action == SyncObject.FIX_OWNER: log('set owner %s.%s (%d.%d) %s' % (self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.src_stat.uid, self.src_stat.gid, self.dest_path)) vnode.set_owner() if fix_action & SyncObject.FIX_MODE: log('set mode %04o %s' % (self.src_stat.mode & 07777, self.dest_path)) vnode.set_permissions() # run .post script, if needed # Note: for dirs, it is run from overlay._walk_subtree() if need_run and not self.src_stat.is_dir(): self.run_script(post_dict) return True
def harddelete(self): '''delete existing entry''' if synctool.lib.DRY_RUN: not_str = 'not ' else: not_str = '' stdout('%sdeleting %s' % (not_str, self.name)) unix_out('rm %s' % self.name) terse(synctool.lib.TERSE_DELETE, self.name) if not synctool.lib.DRY_RUN: verbose(' os.unlink(%s)' % self.name) try: os.unlink(self.name) except OSError as err: error('failed to delete %s : %s' % (self.name, err.strerror)) terse(synctool.lib.TERSE_FAIL, 'delete %s' % self.name) else: log('deleted %s' % self.name)
def check(self): '''check differences between src and dest, Return a FIX_xxx code ''' # src_path is under $overlay/ # dest_path is in the filesystem vnode = None if not self.dest_stat.exists(): stdout('%s does not exist' % self.dest_path) return SyncObject.FIX_CREATE src_type = self.src_stat.filetype() dest_type = self.dest_stat.filetype() if src_type != dest_type: # entry is of a different file type vnode = self.vnode_obj() stdout('%s should be a %s' % (self.dest_path, vnode.typename())) terse(synctool.lib.TERSE_WARNING, 'wrong type %s' % self.dest_path) return SyncObject.FIX_TYPE vnode = self.vnode_obj() if not vnode.compare(self.src_path, self.dest_stat): # content is different; change the entire object log('updating %s' % self.dest_path) return SyncObject.FIX_UPDATE # check ownership and permissions and time # rectify if needed fix_action = 0 if ((self.src_stat.uid != self.dest_stat.uid) or (self.src_stat.gid != self.dest_stat.gid)): stdout('%s should have owner %s.%s (%d.%d), ' 'but has %s.%s (%d.%d)' % (self.dest_path, self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.src_stat.uid, self.src_stat.gid, self.dest_stat.ascii_uid(), self.dest_stat.ascii_gid(), self.dest_stat.uid, self.dest_stat.gid)) terse(synctool.lib.TERSE_OWNER, '%s.%s %s' % (self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.dest_path)) fix_action = SyncObject.FIX_OWNER if self.src_stat.mode != self.dest_stat.mode: stdout('%s should have mode %04o, but has %04o' % (self.dest_path, self.src_stat.mode & 07777, self.dest_stat.mode & 07777)) terse(synctool.lib.TERSE_MODE, '%04o %s' % (self.src_stat.mode & 07777, self.dest_path)) fix_action |= SyncObject.FIX_MODE # FIXME check times for other objects too, but # FIXME not for symlinks # FIXME not for directories (change when you add files ...) if synctool.param.SYNC_TIMES and self.src_stat.is_file(): # FIXME do not call stat() again / SyncStat should have times self.src_stattime = os.lstat(self.src_path) self.dest_stattime = os.lstat(self.dest_path) if (int(self.src_stattime.st_mtime) != int(self.dest_stattime.st_mtime)): stdout('%s has wrong timestamp' % self.dest_path) terse(synctool.lib.TERSE_MODE, ('%s has wrong timestamp' % self.dest_path)) fix_action |= SyncObject.FIX_TIME return fix_action
def check(self): '''check differences between src and dest, and fix it when not a dry run Return pair: updated, metadata_updated''' # src_path is under $overlay/ # dest_path is in the filesystem vnode = None if not self.dest_stat.exists(): stdout('%s does not exist' % self.dest_path) log('creating %s' % self.dest_path) vnode = self.vnode_obj() vnode.fix() return True, False src_type = self.src_stat.filetype() dest_type = self.dest_stat.filetype() if src_type != dest_type: # entry is of a different file type vnode = self.vnode_obj() stdout('%s should be a %s' % (self.dest_path, vnode.typename())) terse(synctool.lib.TERSE_WARNING, 'wrong type %s' % self.dest_path) log('fix type %s' % self.dest_path) vnode.fix() return True, False vnode = self.vnode_obj() if not vnode.compare(self.src_path, self.dest_stat): # content is different; change the entire object log('updating %s' % self.dest_path) vnode.fix() return True, False # check ownership and permissions # rectify if needed meta_updated = False if ((self.src_stat.uid != self.dest_stat.uid) or (self.src_stat.gid != self.dest_stat.gid)): stdout('%s should have owner %s.%s (%d.%d), ' 'but has %s.%s (%d.%d)' % (self.dest_path, self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.src_stat.uid, self.src_stat.gid, self.dest_stat.ascii_uid(), self.dest_stat.ascii_gid(), self.dest_stat.uid, self.dest_stat.gid)) terse(synctool.lib.TERSE_OWNER, '%s.%s %s' % (self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.dest_path)) log('set owner %s.%s (%d.%d) %s' % (self.src_stat.ascii_uid(), self.src_stat.ascii_gid(), self.src_stat.uid, self.src_stat.gid, self.dest_path)) vnode.set_owner() meta_updated = True if self.src_stat.mode != self.dest_stat.mode: stdout('%s should have mode %04o, but has %04o' % (self.dest_path, self.src_stat.mode & 07777, self.dest_stat.mode & 07777)) terse(synctool.lib.TERSE_MODE, '%04o %s' % (self.src_stat.mode & 07777, self.dest_path)) log('set mode %04o %s' % (self.src_stat.mode & 07777, self.dest_path)) vnode.set_permissions() meta_updated = True # set owner/permissions do not trigger .post scripts return False, meta_updated