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 metadata[X_OBJECT_TYPE] == MARKER_DIR: if os.path.exists(os.path.join(self.datadir, self.obj)) and \ not os.path.isdir(os.path.join(self.datadir, self.obj)): os.unlink(os.path.join(self.datadir, self.obj)) mkdirs(os.path.join(self.datadir, self.obj)) os.chown(os.path.join(self.datadir, self.obj), self.uid, self.gid) self.put_metadata(metadata) self.data_file = self.datadir + '/' + self.obj return True #Check if directory already exists. if self.is_dir: logging.error('Directory already exists %s/%s' % \ (self.datadir , self.obj)) return False #metadata['name'] = self.name timestamp = normalize_timestamp(metadata[X_TIMESTAMP]) write_metadata(fd, 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(tmp_path, metadata[X_TIMESTAMP]): return False #print 'Gaurav put tmppath', tmppath, os.path.join(self.datadir, #self.obj+extension) #invalidate_hash(os.path.dirname(self.datadir)) renamer(tmppath, os.path.join(self.datadir, self.obj + extension)) os.chown(os.path.join(self.datadir, self.obj + extension), \ self.uid, self.gid) self.metadata = metadata self.data_file = self.datadir + '/' + self.obj + extension return True
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
def update_object(self, metadata): obj_path = self.datadir + '/' + self.obj write_metadata(obj_path, metadata) self.metadata = metadata
def put_metadata(self, metadata): obj_path = self.datadir + '/' + self.obj write_metadata(obj_path, metadata) self.metadata = metadata
def update_account(self, metadata): acc_path = self.datadir write_metadata(acc_path, metadata) self.metadata = metadata
def update_container(self, metadata): cont_path = self.datadir write_metadata(cont_path, metadata) self.metadata = metadata
def put_metadata(self, metadata): """ Write metadata to directory/container. """ write_metadata(self.datadir, metadata) self.metadata = metadata