def _get_dev_path(self, device): """ Return the path to a device, checking to see that it is a proper mount point based on a configuration parameter. :param device: name of target device :returns: full path to the device, None if the path to the device is not a proper mount point. """ if self.mount_check and not mount(self.devices, device): dev_path = None else: dev_path = os.path.join(self.devices, device) return dev_path
def _get_dev_path(self, device): """ Return the path to a device, checking to see that it is a proper mount point based on a configuration parameter. :param device: name of target device :returns: full path to the device, None if the path to the device is not a proper mount point. """ if self.mount_check and not mount(self.devices, device): dev_path = None else: dev_path = os.path.join(self.devices, device) return dev_path
def __init__(self, path, device, partition, account, container, obj, logger, keep_data_fp=False, disk_chunk_size=DEFAULT_DISK_CHUNK_SIZE, bytes_per_sync=DEFAULT_BYTES_PER_SYNC, iter_hook=None, threadpool=None, obj_dir='objects', mount_check=False, disallowed_metadata_keys=None, uid=DEFAULT_UID, gid=DEFAULT_GID): if mount_check and not mount(path, device): raise DiskFileDeviceUnavailable() self.disk_chunk_size = disk_chunk_size self.bytes_per_sync = bytes_per_sync self.iter_hook = iter_hook self.threadpool = threadpool or ThreadPool(nthreads=0) obj = obj.strip(os.path.sep) if os.path.sep in obj: self._obj_path, self._obj = os.path.split(obj) else: self._obj_path = '' self._obj = obj if self._obj_path: self.name = os.path.join(container, self._obj_path) else: self.name = container # Absolute path for object directory. self.datadir = os.path.join(path, device, self.name) self.device_path = os.path.join(path, device) self._container_path = os.path.join(path, device, container) if _use_put_mount: self.put_datadir = os.path.join(self.device_path + '_PUT', self.name) else: self.put_datadir = self.datadir self._is_dir = False self.logger = logger self.metadata = {} self.meta_file = None self.fp = None self.iter_etag = None self.started_at_0 = False self.read_to_eof = False self.quarantined_dir = None self.keep_cache = False self.uid = int(uid) self.gid = int(gid) self.suppress_file_closing = False # Don't store a value for data_file until we know it exists. self.data_file = None data_file = os.path.join(self.put_datadir, self._obj) try: stats = do_stat(data_file) except OSError as err: if err.errno == errno.ENOTDIR: return else: if not stats: return self.data_file = data_file self._is_dir = stat.S_ISDIR(stats.st_mode) self.metadata = read_metadata(data_file) if not self.metadata: create_object_metadata(data_file) self.metadata = read_metadata(data_file) if not validate_object(self.metadata): create_object_metadata(data_file) self.metadata = read_metadata(data_file) self._filter_metadata() if keep_data_fp: if not self._is_dir: # The caller has an assumption that the "fp" field of this # object is an file object if keep_data_fp is set. However, # this implementation of the DiskFile object does not need to # open the file for internal operations. So if the caller # requests it, we'll just open the file for them. self.fp = do_open(data_file, 'rb') else: self.fp = Fake_file(data_file)