Ejemplo n.º 1
0
    def copyRecentFilesIntoCache(self, transfer_q: MaxPrioQueue):
        print(Col.b('Transfering files...'))
        while not transfer_q.empty() and not self.disk.isFull(
                use_threshold=True):
            timestamp, (inode, file_size) = transfer_q.pop_nowait()
            path = self.vfs._inode_path_map[inode].src

            # skip symbolic links for now
            if os.path.islink(path):
                continue

            try:
                dest = self.disk.cp2Cache(path)
            except NotEnoughSpaceError:
                # filter the Queue
                purged_list = MaxPrioQueue()
                while not transfer_q.empty():
                    timestamp_i, (inode_i, size_i) = transfer_q.pop_nowait()
                    if size_i < file_size:
                        purged_list.push_nowait(
                            (timestamp_i, (inode_i, size_i)))
                transfer_q = purged_list

        # print summary
        diskUsage, usedCache, maxCache = self.disk.getCurrentStatus()
        diskUsage = Col.by(f'{diskUsage:.8f}%')
        usedCache = Col.by(f'{Col.BY}{formatByteSize(usedCache)} ')
        maxCache = Col.by(f'{formatByteSize(maxCache)} ')
        copySummary = \
         Col.bw(f'Finished transfering {self.disk.in_cache.qsize()} elements.\nCache is now {diskUsage} ') + Col.bw(
          'full') + \
         Col.bw(f" (used: {usedCache}") + Col.bw(f" / {maxCache}") + Col.bw(")")
        print(copySummary)
Ejemplo n.º 2
0
	def printSummary(self):
		diskUsage, usedCache, maxCache = self.getCurrentStatus()
		diskUsage = Col.by(f'{diskUsage:.8f}%')
		usedCache = Col.by(f'{Col.BY}{formatByteSize(usedCache)} ')
		maxCache = Col.by(f'{formatByteSize(maxCache)} ')
		copySummary = \
			Col.bw(
				f'Cache is currently storing {self.in_cache.qsize()} elements and is {diskUsage} ') + Col.bw(
				'full\n') + \
			Col.bw(f" (used: {usedCache}") + Col.bw(f" / {maxCache}") + Col.bw(")")
		print(copySummary)
Ejemplo n.º 3
0
	async def open(self, inode: int, flags: int, ctx):
		# return early for already opened fd
		print(f'open({inode}, {flags}, {ctx})')

		if self.vfs.already_open(inode):
			fd = self.vfs._inode_fd_map[inode]
			self.vfs._fd_open_count[fd] += 1
			print(Col.by(f'open: (fd, inode): ({fd}, {inode})'))
			return pyfuse3.FileInfo(fh=fd)

		# disable creation handling here
		assert flags & os.O_CREAT == 0

		try:
			f: Path = self._inode_to_path(inode)
			info: FileInfo = self.vfs._inode_path_map[inode]

			# fetch file from remote if not in cache already
			if not f.exists():
				f_src = self.disk.toSrcPath(f)
				# self.remote.makeAvailable()
				self.__fetchFile(f_src, info.entry.st_size)

			# File is in Cache now
			fd: int = os.open(f, flags)
			info.updateEntry(fd=fd)
		except OSError as exc:
			raise FUSEError(exc.errno)

		self.vfs._inode_fd_map[inode] = fd
		self.vfs._fd_inode_map[fd] = inode
		self.vfs._fd_open_count[fd] = 1

		return pyfuse3.FileInfo(fh=fd)
Ejemplo n.º 4
0
	def _cp2Dir(src: Path, dst: Path):
		"""
		Create a copy of `src` in `dst` while also keeping meta-data.
		Creates parent directories on the fly.
		Ignores special files.

		:arg src: original File
		:arg dst: destination File to have the same attributes and contents of `src` after the call
		:returns: Path of copied file in cacheDir
		"""
		if src == dst:
			# same File no need for copying,
			# file should exist already too as self.__canStore would throw errors otherwise
			return src
		src_mode = os.stat(src).st_mode

		if src.is_dir():
			Disk.cpdir(src, dst)
		elif src.is_file():
			if not dst.parent.exists():
				Disk.cpdir(src.parent, dst.parent)
			shutil.copy2(src, dst)
		else:
			msg = Col.by(f' Unrecognized filetype: {src} -> ignoring')
			log.error(msg)
			raise IOError(msg)

		# book-keeping of file-attributes (also takes care of parent dirs having wrong modes from previous runs)
		dst.chmod(src_mode)
		shutil.copystat(src, dst)
		return dst
Ejemplo n.º 5
0
	async def releasedir(self, fh):
		# same as normal release() no more fh are using it
		print(Col.by(f"releasing dir: {self.vfs.inode_to_path(fh)}"))
Ejemplo n.º 6
0
	async def opendir(self, inode, ctx):
		print(Col.by(f"opendir: {self.vfs.inode_to_path(inode)}"))
		# ctx contains gid, uid, pid and umask
		return inode