Example #1
0
    def set_times(self):
        '''set access and modification times'''

        # only mtime is shown
        verbose(dryrun_msg('  os.utime(%s, %s)' %
                           (self.name, print_timestamp(self.stat.mtime))))
        # print timestamp in other format
        dt = datetime.datetime.fromtimestamp(self.stat.mtime)
        time_str = dt.strftime('%Y%m%d%H%M.%S')
        unix_out('touch -t %s %s' % (time_str, self.name))
        if not synctool.lib.DRY_RUN:
            try:
                os.utime(self.name, (self.stat.atime, self.stat.mtime))
            except OSError as err:
                error('failed to set utime on %s : %s' % (self.name,
                                                          err.strerror))
                terse(TERSE_FAIL, 'utime %s' % self.name)
Example #2
0
    def set_times(self):
        # type: () -> None
        '''set access and modification times'''

        # only mtime is shown
        verbose(dryrun_msg('  os.utime(%s, %s)' %
                           (self.name, print_timestamp(self.stat.mtime))))
        # print timestamp in other format
        dt = datetime.datetime.fromtimestamp(self.stat.mtime)
        time_str = dt.strftime('%Y%m%d%H%M.%S')
        unix_out('touch -t %s %s' % (time_str, self.name))
        if not synctool.lib.DRY_RUN:
            try:
                os.utime(self.name, (self.stat.atime, self.stat.mtime))
            except OSError as err:
                error('failed to set utime on %s : %s' % (self.name,
                                                          err.strerror))
                terse(TERSE_FAIL, 'utime %s' % self.name)
Example #3
0
    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

        # check times, but not for symlinks, directories
        if (synctool.param.SYNC_TIMES and
                not self.src_stat.is_link() and not self.src_stat.is_dir() and
                self.src_stat.mtime != self.dest_stat.mtime):
            stdout('%s has wrong timestamp %s' %
                   (self.dest_path, print_timestamp(self.dest_stat.mtime)))
            terse(synctool.lib.TERSE_MODE, ('%s has wrong timestamp' %
                                            self.dest_path))
            fix_action |= SyncObject.FIX_TIME

        return fix_action
Example #4
0
    def check(self):
        # type: () -> int
        '''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

        # check times, but not for symlinks, directories
        if (synctool.param.SYNC_TIMES and
                not self.src_stat.is_link() and not self.src_stat.is_dir() and
                self.src_stat.mtime != self.dest_stat.mtime):
            stdout('%s has wrong timestamp %s' %
                   (self.dest_path, print_timestamp(self.dest_stat.mtime)))
            terse(synctool.lib.TERSE_MODE, ('%s has wrong timestamp' %
                                            self.dest_path))
            fix_action |= SyncObject.FIX_TIME

        return fix_action