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 unlinkold(self, timestamp): """ Remove any older versions of the object file. Any file that has an older timestamp than timestamp will be deleted. :param timestamp: timestamp to compare with each file """ timestamp = normalize_timestamp(timestamp) for fname in do_listdir(self.datadir): if fname < timestamp: try: do_unlink(os.path.join(self.datadir, fname)) except OSError, err: # pragma: no cover if err.errno != errno.ENOENT: raise
def mkstemp(self): """Contextmanager to make a temporary file.""" if not os.path.exists(self.tmpdir): mkdirs(self.tmpdir) fd, tmppath = mkstemp(dir=self.tmpdir) try: yield fd, tmppath finally: try: do_close(fd) except OSError: pass try: do_unlink(tmppath, log=False) except OSError: pass
def unlink(self): """ Remove the file. """ #Marker dir. if self.is_dir: rmdirs(os.path.join(self.datadir, self.obj)) if not os.path.isdir(os.path.join(self.datadir, self.obj)): self.metadata = {} self.data_file = None else: logging.error('Unable to delete dir %s' % os.path.join(self.datadir, self.obj)) return for fname in do_listdir(self.datadir): if fname == self.obj: try: do_unlink(os.path.join(self.datadir, fname)) except OSError, err: if err.errno != errno.ENOENT: raise