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
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
def create_dir_object(self, dir_path): # TODO: if object already exists??? if os.path.exists(dir_path) and not os.path.isdir(dir_path): self.logger.error("Deleting file %s", dir_path) do_unlink(dir_path) # If dir aleady exist just override metadata. mkdirs(dir_path) do_chown(dir_path, self.uid, self.gid) create_object_metadata(dir_path) return True
def create_dir_object(self, dir_path): #TODO: if object already exists??? if os.path.exists(dir_path) and not os.path.isdir(dir_path): self.logger.error("Deleting file %s", dir_path) do_unlink(dir_path) #If dir aleady exist just override metadata. mkdirs(dir_path) do_chown(dir_path, self.uid, self.gid) create_object_metadata(dir_path) return True