Beispiel #1
0
    def put(self, fd, tmppath, metadata, extension=''):
        """
        Finalize writing the file on disk, and renames it from the temp file to
        the real location.  This should be called after the data has been
        written to the temp file.

        :params fd: file descriptor of the temp file
        :param tmppath: path to the temporary file being used
        :param metadata: dictionary of metadata to be written
        :param extention: extension to be used when making the file
        """
        #Marker dir.
        if extension == '.ts':
            return True
        if extension == '.meta':
            self.put_metadata(metadata)
            return True
        else:
            extension = ''
        if metadata[X_OBJECT_TYPE] == MARKER_DIR:
            self.create_dir_object(os.path.join(self.datadir, self.obj))
            self.put_metadata(metadata)
            self.data_file = self.datadir + '/' + self.obj
            return True
        #Check if directory already exists.
        if self.is_dir:
            self.logger.error('Directory already exists %s/%s' % \
                          (self.datadir , self.obj))
            return False
        #metadata['name'] = self.name
        timestamp = normalize_timestamp(metadata[X_TIMESTAMP])
        write_metadata(tmppath, metadata)
        if X_CONTENT_LENGTH in metadata:
            self.drop_cache(fd, 0, int(metadata[X_CONTENT_LENGTH]))
        tpool.execute(os.fsync, fd)
        if self.obj_path:
            dir_objs = self.obj_path.split('/')
            tmp_path = ''
            if len(dir_objs):
                for dir_name in dir_objs:
                    if tmp_path:
                        tmp_path = tmp_path + '/' + dir_name
                    else:
                        tmp_path = dir_name
                    if not self.create_dir_object(os.path.join(self.container_path,
                            tmp_path)):
                        self.logger.error("Failed in subdir %s",\
                                        os.path.join(self.container_path,tmp_path))
                        return False

        renamer(tmppath, os.path.join(self.datadir,
                                      self.obj + extension))
        do_chown(os.path.join(self.datadir, self.obj + extension), \
              self.uid, self.gid)
        self.metadata = metadata
        #self.logger.error("Meta %s", self.metadata)
        self.data_file = self.datadir + '/' + self.obj + extension
        return True
Beispiel #2
0
    def put(self, fd, tmppath, metadata, extension=''):
        """
        Finalize writing the file on disk, and renames it from the temp file to
        the real location.  This should be called after the data has been
        written to the temp file.

        :params fd: file descriptor of the temp file
        :param tmppath: path to the temporary file being used
        :param metadata: dictionary of metadata to be written
        :param extention: extension to be used when making the file
        """
        #Marker dir.
        if extension == '.ts':
            return True
        if extension == '.meta':
            self.put_metadata(metadata)
            return True
        else:
            extension = ''
        if metadata[X_OBJECT_TYPE] == MARKER_DIR:
            self.create_dir_object(os.path.join(self.datadir, self.obj))
            self.put_metadata(metadata)
            self.data_file = self.datadir + '/' + self.obj
            return True
        #Check if directory already exists.
        if self.is_dir:
            self.logger.error('Directory already exists %s/%s' % \
                          (self.datadir , self.obj))
            return False
        #metadata['name'] = self.name
        timestamp = normalize_timestamp(metadata[X_TIMESTAMP])
        write_metadata(tmppath, metadata)
        if X_CONTENT_LENGTH in metadata:
            self.drop_cache(fd, 0, int(metadata[X_CONTENT_LENGTH]))
        tpool.execute(os.fsync, fd)
        if self.obj_path:
            dir_objs = self.obj_path.split('/')
            tmp_path = ''
            if len(dir_objs):
                for dir_name in dir_objs:
                    if tmp_path:
                        tmp_path = tmp_path + '/' + dir_name
                    else:
                        tmp_path = dir_name
                    if not self.create_dir_object(
                            os.path.join(self.container_path, tmp_path)):
                        self.logger.error("Failed in subdir %s",\
                                        os.path.join(self.container_path,tmp_path))
                        return False

        renamer(tmppath, os.path.join(self.datadir, self.obj + extension))
        do_chown(os.path.join(self.datadir, self.obj + extension), \
              self.uid, self.gid)
        self.metadata = metadata
        #self.logger.error("Meta %s", self.metadata)
        self.data_file = self.datadir + '/' + self.obj + extension
        return True
Beispiel #3
0
 def test_write_metadata(self):
     path = "/tmp/foo/w"
     orig_d = { 'bar' : 'foo' }
     utils.write_metadata(path, orig_d)
     xkey = _xkey(path, utils.METADATA_KEY)
     assert len(_xattrs.keys()) == 1
     assert xkey in _xattrs
     assert orig_d == pickle.loads(_xattrs[xkey])
     assert _xattr_op_cnt['set'] == 1
Beispiel #4
0
    def put(self, metadata):
        """
        Create and write metatdata to directory/container.
        :param metadata: Metadata to write.
        """
        if not self.dir_exists:
            mkdirs(self.datadir)

        os.chown(self.datadir, self.uid, self.gid)
        write_metadata(self.datadir, metadata)
        self.metadata = metadata
        self.dir_exists = True
Beispiel #5
0
    def put(self, metadata):
        """
        Create and write metatdata to directory/container.
        :param metadata: Metadata to write.
        """
        if not self.dir_exists:
            mkdirs(self.datadir)

        os.chown(self.datadir, self.uid, self.gid)
        write_metadata(self.datadir, metadata)
        self.metadata = metadata
        self.dir_exists = True
Beispiel #6
0
 def test_write_metadata_err(self):
     path = "/tmp/foo/w"
     orig_d = { 'bar' : 'foo' }
     xkey = _xkey(path, utils.METADATA_KEY)
     _xattr_err[xkey] = errno.EOPNOTSUPP
     try:
         utils.write_metadata(path, orig_d)
     except IOError as e:
         assert e.errno == errno.EOPNOTSUPP
         assert len(_xattrs.keys()) == 0
         assert _xattr_op_cnt['set'] == 1
     else:
         self.fail("Expected an IOError exception on write")
Beispiel #7
0
 def test_write_metadata_multiple(self):
     # At 64 KB an xattr key/value pair, this should generate three keys.
     path = "/tmp/foo/w"
     orig_d = { 'bar' : 'x' * 150000 }
     utils.write_metadata(path, orig_d)
     assert len(_xattrs.keys()) == 3, "Expected 3 keys, found %d" % len(_xattrs.keys())
     payload = ''
     for i in range(0,3):
         xkey = _xkey(path, "%s%s" % (utils.METADATA_KEY, i or ''))
         assert xkey in _xattrs
         assert len(_xattrs[xkey]) <= utils.MAX_XATTR_SIZE
         payload += _xattrs[xkey]
     assert orig_d == pickle.loads(payload)
     assert _xattr_op_cnt['set'] == 3, "%r" % _xattr_op_cnt
Beispiel #8
0
 def update_object(self, metadata):
     obj_path = self.datadir + "/" + self.obj
     write_metadata(obj_path, metadata)
     self.metadata = metadata
Beispiel #9
0
 def put_metadata(self, metadata):
     """
     Write metadata to directory/container.
     """
     write_metadata(self.datadir, metadata)
     self.metadata = metadata
Beispiel #10
0
 def update_account(self, metadata):
     acc_path = self.datadir
     write_metadata(acc_path, metadata)
     self.metadata = metadata
Beispiel #11
0
 def update_metadata(self, metadata):
     self.metadata.update(metadata)
     write_metadata(self.datadir, self.metadata)
Beispiel #12
0
 def update_container(self, metadata):
     cont_path = self.datadir
     write_metadata(cont_path, metadata)
     self.metadata = metadata
Beispiel #13
0
 def put_metadata(self, metadata):
     """
     Write metadata to directory/container.
     """
     write_metadata(self.datadir, metadata)
     self.metadata = metadata
Beispiel #14
0
 def update_container(self, metadata):
     cont_path = self.datadir
     write_metadata(cont_path, metadata)
     self.metadata = metadata
Beispiel #15
0
 def put_metadata(self, metadata):
     obj_path = self.datadir + "/" + self.obj
     write_metadata(obj_path, metadata)
     self.metadata = metadata
Beispiel #16
0
 def update_object(self, metadata):
     obj_path = self.datadir + '/' + self.obj
     write_metadata(obj_path, metadata)
     self.metadata = metadata
Beispiel #17
0
 def put_metadata(self, metadata):
     obj_path = self.datadir + '/' + self.obj
     write_metadata(obj_path, metadata)
     self.metadata = metadata
Beispiel #18
0
 def update_metadata(self, metadata):
     self.metadata.update(metadata)
     write_metadata(self.datadir, self.metadata)
Beispiel #19
0
 def update_account(self, metadata):
     acc_path = self.datadir
     write_metadata(acc_path, metadata)
     self.metadata = metadata