Пример #1
0
 def rename(self, path, path1):
     logging.info('rename: '+path)        
     try:
         frs = self.find_nonfiles_by_path(path, 'file')
         if frs[0] == 'dir':
             logging.error('rename on dir is not supported yet: '+path+' to '+path1)
             return -errno.ENOSYS
         
         if frs[0] == 'file':
             logging.info('rename from ' + path + ' to ' + path1)
             tags0 = tagfsutils.path2tags(path, 'file')[1]
             tags1 = tagfsutils.path2tags(path1, 'file')[1]
             f = self.tdb.files[frs[1][0]]
             if tags1[-1] != tags0[-1]:
                 logging.info('rename from '+self.lldir+f.getfullname()+' to '+self.lldir+f.fuuid+'_'+tags1[-1])
                 os.rename(self.lldir+f.getfullname(), self.lldir+f.fuuid+'_'+tags1[-1])                    
                 f.fname = tags1[-1]
             rmtags = list(set(tags0[0:-1]) - set(tags1[0:-1]))
             addtags = list(set(tags1[0:-1]) - set(tags0[0:-1]))
             try:
                 self.tdb.change_file_tags(f.fuuid, rmtags, addtags)
                 self.tdb.store_db(self.lldir+TagDB.DefaultMetaDBFile)
             except Exception as e:
                 logging.error('change file tag failed from +'+str(addtags)+' -'+str(rmtags))
                 os.rename(self.lldir+f.fuuid+'_'+tags0[-1], self.lldir+f.fuuid+'_'+tags1[-1])
                 raise e
         else:
             logging.error('rename fault error')
             return -errno.EFAULT
     except Exception as e:
         logging.error('rename error'+str(e))
         return -errno.ENOENT
Пример #2
0
 def add_tags_by_path(self, path):
     tset = tagfsutils.path2tags(path, 'dir')[1]
     self.logger.info('add tags by path: '+str(tset))
     # TODO: check unique for tags!!! IMPORTANT TODO
     for t in tset:
         if t not in self.tags:
             self.tags[t] = {}
Пример #3
0
    def getxattr(self, path, name, size):
        if name != 'tags':
            return -errno.ENODATA  # should be -errno.ENOATTR
        tags = ''
        if path == '/':
            tags = '/'.join([t for t in self.tdb.tags.keys() if t != '/'])
        else:
            try:
                fs = self.find_nonfiles_by_path(path)
            except (TagDB.NoTagException, TagDB.NoFileException):
                logging.error('getxattr: no ent ' + path)
                return -errno.ENOENT

            if fs[0] == 'dir':
                if len(fs[1]) != 0:
                    pts = set(tagfsutils.path2tags(path, 'dir')[1])

                    # make sure lambda be executed at least once and also for first time call
                    ts = reduce(
                        lambda irt, f: irt | set(self.tdb.files[f[0]].tags) -
                        pts, [set()] + fs[1])
                    tags = '/'.join(ts)
            else:
                f = self.tdb.files[fs[1][0]]
                tags = '/'.join(f.tags)

        if size == 0:
            # tags string size
            return len(tags)
        return tags
Пример #4
0
 def getxattr(self, path, name, size):
     if name != 'tags':
         return -errno.ENODATA # should be -errno.ENOATTR
     tags = ''
     if path == '/':
         tags = '/'.join([t for t in self.tdb.tags.keys() if t != '/'])
     else:
         try:
             fs = self.find_nonfiles_by_path(path)               
         except (TagDB.NoTagException, TagDB.NoFileException):
             logging.error('getxattr: no ent '+path)
             return -errno.ENOENT
         
         if fs[0] == 'dir':
             if len(fs[1]) != 0:                
                 pts = set(tagfsutils.path2tags(path, 'dir')[1])
                 
                 # make sure lambda be executed at least once and also for first time call                    
                 ts = reduce(lambda irt,f: irt | set(self.tdb.files[f[0]].tags)-pts, [set()]+fs[1])
                 tags = '/'.join(ts)                
         else:
             f = self.tdb.files[fs[1][0]]
             tags = '/'.join(f.tags)
     
     if size == 0:
         # tags string size
         return len(tags)
     return tags
Пример #5
0
    def rename(self, path, path1):
        logging.info('rename: ' + path)
        try:
            frs = self.find_nonfiles_by_path(path, 'file')
            if frs[0] == 'dir':
                logging.error('rename on dir is not supported yet: ' + path +
                              ' to ' + path1)
                return -errno.ENOSYS

            if frs[0] == 'file':
                logging.info('rename from ' + path + ' to ' + path1)
                tags0 = tagfsutils.path2tags(path, 'file')[1]
                tags1 = tagfsutils.path2tags(path1, 'file')[1]
                f = self.tdb.files[frs[1][0]]
                if tags1[-1] != tags0[-1]:
                    logging.info('rename from ' + self.lldir +
                                 f.getfullname() + ' to ' + self.lldir +
                                 f.fuuid + '_' + tags1[-1])
                    os.rename(self.lldir + f.getfullname(),
                              self.lldir + f.fuuid + '_' + tags1[-1])
                    f.fname = tags1[-1]
                rmtags = list(set(tags0[0:-1]) - set(tags1[0:-1]))
                addtags = list(set(tags1[0:-1]) - set(tags0[0:-1]))
                try:
                    self.tdb.change_file_tags(f.fuuid, rmtags, addtags)
                    self.tdb.store_db(self.lldir + TagDB.DefaultMetaDBFile)
                except Exception as e:
                    logging.error('change file tag failed from +' +
                                  str(addtags) + ' -' + str(rmtags))
                    os.rename(self.lldir + f.fuuid + '_' + tags0[-1],
                              self.lldir + f.fuuid + '_' + tags1[-1])
                    raise e
            else:
                logging.error('rename fault error')
                return -errno.EFAULT
        except Exception as e:
            logging.error('rename error' + str(e))
            return -errno.ENOENT
Пример #6
0
 def rm_file_tags_by_path(self, fuuid, path):
     tset = tagfsutils.path2tags(path, 'file')[1]
     del tset[-1]                
     self.__rm_ftags(fuuid, tset)
     f = self.files[fuuid]
     if not self.check_unique_file(f.tags, f.fname, True):
         self.logger.error('not unique in rm file tags by path'+str(f.tags))
         self.__undo_rm_ftags(fuuid, tset)            
         raise NoUniqueTagException(
                 'Can not make file unique if remove tags. ' \
                 + 'file: ' + fuuid + ' tags: ' + str(tset), tset)
     #if path != '/':
         #if len(f.tags) == 0:
             #self.tags['/'][fuuid] = f
     if len(f.tags) == 0 and fuuid not in self.tags['/']:
         del self.files[fuuid]
         return (True, f.getfullname())
     return (False,)
Пример #7
0
    def mknod(self, path, mode, dev):
        logging.info('Create new inode: ' + path)
        ftags_rs = tagfsutils.path2tags(path, 'file')

        if ftags_rs[0] == 'file':
            logging.info('Want to create a file')
            ftags = ftags_rs[1][0:-1]
            fname = ftags_rs[1][-1]
            import uuid
            fuuid = uuid.uuid4().hex
            try:
                self.tdb.add_file(fuuid, fname, ftags)
            except:
                logging.error('Want create a file that conflicts with tags')
                e = OSError()
                e.errno = errno.EEXIST  # (TODO: find a correct errno)
                raise e
        else:
            logging.info('Want to create a dir')
            self.mkdir(path, mode)
        self.tdb.store_db(self.lldir + TagDB.DefaultMetaDBFile)
Пример #8
0
 def mknod(self, path, mode, dev):
     logging.info('Create new inode: '+path)
     ftags_rs = tagfsutils.path2tags(path, 'file')
                 
     if ftags_rs[0] == 'file':
         logging.info('Want to create a file')
         ftags = ftags_rs[1][0:-1]
         fname = ftags_rs[1][-1]
         import uuid
         fuuid = uuid.uuid4().hex
         try:
             self.tdb.add_file(fuuid, fname, ftags)
         except:
             logging.error('Want create a file that conflicts with tags')
             e = OSError()
             e.errno = errno.EEXIST # (TODO: find a correct errno)
             raise e
     else:
         logging.info('Want to create a dir')
         self.mkdir(path, mode)
     self.tdb.store_db(self.lldir+TagDB.DefaultMetaDBFile)
Пример #9
0
 def rm_tags_by_path(self, path):
     tset = tagfsutils.path2tags(path, 'dir')[1]
     for t in tset:
         if len(self.tags[t]) == 0:
             del self.tags[t]
Пример #10
0
        def __init__(self, path, flags, *mode):
            logging.info('open: ' + path + ' flags: ' + str(flags))
            self.tagfs = TagFS.cur_tagfs
            self.path = path
            self.flags = flags
            self.mode = mode
            self.direct_io = True
            self.keep_cache = False
            try:
                # can a directory be opened? Yes, but when reading, errors are there.
                f = self.tagfs.find_nonfiles_by_path(path)
                if f[0] == 'dir':
                    self.filetype = 'dir'
                    self.dircont = f[1]

                if f[0] == 'file':
                    self.filetype = 'file'
                    self.file = os.fdopen(
                        os.open(
                            self.tagfs.lldir +
                            self.tagfs.tdb.files[f[1][0]].getfullname(), flags,
                            *mode), _flags2mode(flags))
                    self.fd = self.file.fileno()
            except (TagDB.NoTagException, TagDB.NameConflictionException):
                e = OSError()
                e.errno = errno.ENOENT
                logging.error('open: no tag: ' + path + ' flags: ' +
                              str(flags))
                raise e
            except TagDB.NoUniqueTagException:
                # System error: no unique id for path/file
                logging.error(
                    'System error: no unique id for path/file: path=' + path)
                e = OSError()
                e.errno = errno.ENOENT
                raise e
            except TagDB.NoFileException:
                logging.info('Create new file')
                if flags | os.O_CREAT == flags:
                    ftags_rs = tagfsutils.path2tags(path, 'file')
                    if ftags_rs[0] != 'file':
                        logging.error('Want to create a directory')
                        e = OSError()
                        e.errno = errno.EISDIR  # (TODO: check the correct errno)
                        raise e
                    ftags = ftags_rs[1][0:-1]
                    fname = ftags_rs[1][-1]
                    import uuid
                    fuuid = uuid.uuid4().hex
                    try:
                        logging.info('add file: ' + fname + ' ' + str(ftags))
                        self.tagfs.tdb.add_file(fuuid, fname, ftags)
                        self.file = os.fdopen(
                            os.open(
                                self.tagfs.lldir +
                                self.tagfs.tdb.files[fuuid].getfullname(),
                                flags, *mode), _flags2mode(flags))
                        self.fd = self.file.fileno()
                        self.filetype = 'file'
                    except TagDB.NoUniqueTagException as ne:
                        logging.error(
                            'Want create a file that conflicts with tags' +
                            ne.msg)
                        e = OSError()
                        e.errno = errno.EEXIST  # (TODO: find a correct errno)
                        raise e
                else:
                    e = OSError()
                    e.errno = errno.ENOENT
                    raise e
Пример #11
0
 def __init__(self, path, flags, *mode):
     logging.info('open: '+path + ' flags: '+str(flags))
     self.tagfs = TagFS.cur_tagfs  
     self.path = path
     self.flags = flags
     self.mode = mode
     self.direct_io = True
     self.keep_cache = False
     try:
         # can a directory be opened? Yes, but when reading, errors are there.                
         f = self.tagfs.find_nonfiles_by_path(path)                
         if f[0] == 'dir':
             self.filetype = 'dir'                    
             self.dircont = f[1]
         
         if f[0] == 'file':
             self.filetype = 'file'
             self.file = os.fdopen(os.open(
                            self.tagfs.lldir + self.tagfs.tdb.files[f[1][0]].getfullname(),
                            flags, *mode), _flags2mode(flags))
             self.fd = self.file.fileno()
     except (TagDB.NoTagException, TagDB.NameConflictionException):
         e = OSError()
         e.errno = errno.ENOENT
         logging.error('open: no tag: '+path+' flags: '+str(flags))
         raise e
     except TagDB.NoUniqueTagException:
         # System error: no unique id for path/file
         logging.error('System error: no unique id for path/file: path='+path)
         e = OSError()
         e.errno = errno.ENOENT
         raise e
     except TagDB.NoFileException:
         logging.info('Create new file')
         if flags | os.O_CREAT == flags:
             ftags_rs = tagfsutils.path2tags(path, 'file')
             if ftags_rs[0] != 'file':
                 logging.error('Want to create a directory')
                 e = OSError()
                 e.errno = errno.EISDIR # (TODO: check the correct errno)
                 raise e
             ftags = ftags_rs[1][0:-1]
             fname = ftags_rs[1][-1]
             import uuid
             fuuid = uuid.uuid4().hex
             try:
                 logging.info('add file: '+fname+' '+str(ftags))
                 self.tagfs.tdb.add_file(fuuid, fname, ftags)                        
                 self.file = os.fdopen(os.open(
                            self.tagfs.lldir + self.tagfs.tdb.files[fuuid].getfullname(),
                            flags, *mode), _flags2mode(flags))
                 self.fd = self.file.fileno()    
                 self.filetype = 'file'                    
             except TagDB.NoUniqueTagException as ne:
                 logging.error('Want create a file that conflicts with tags'+ne.msg)
                 e = OSError()
                 e.errno = errno.EEXIST # (TODO: find a correct errno)
                 raise e
         else:
             e = OSError()
             e.errno = errno.ENOENT
             raise e