Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def entry_attributes(self):
attr = pyfuse3.EntryAttributes()
attr.st_nlink = self.refcount
attr.st_blocks = (self.size + 511) // 512
attr.st_ino = self.id
# Timeout, can effectively be infinite since attribute changes
# are only triggered by the kernel's own requests
attr.attr_timeout = 3600
attr.entry_timeout = 3600
# We want our blocksize for IO as large as possible to get large
# write requests
attr.st_blksize = 128 * 1024
attr.st_mode = self.mode
attr.st_uid = self.uid
attr.st_gid = self.gid
async def statfs(self, ctx):
log.debug('started')
stat_ = pyfuse3.StatvfsData()
# Get number of blocks & inodes
blocks = self.db.get_val("SELECT COUNT(id) FROM objects")
inodes = self.db.get_val("SELECT COUNT(id) FROM inodes")
size = self.db.get_val('SELECT SUM(size) FROM blocks')
if size is None:
size = 0
# file system block size, i.e. the minimum amount of space that can
# be allocated. This doesn't make much sense for S3QL, so we just
# return the average size of stored blocks.
stat_.f_frsize = max(4096, size // blocks) if blocks != 0 else 4096
# This should actually be the "preferred block size for doing IO. However, `df` incorrectly
# interprets f_blocks, f_bfree and f_bavail in terms of f_bsize rather than f_frsize as it
def tst_bug382(self):
dirname = self.newname()
fullname = self.mnt_dir + "/" + dirname
os.mkdir(fullname)
assert stat.S_ISDIR(os.stat(fullname).st_mode)
assert dirname in pyfuse3.listdir(self.mnt_dir)
cmd = ('(%d, %r)' % (pyfuse3.ROOT_INODE, path2bytes(dirname))).encode()
pyfuse3.setxattr('%s/%s' % (self.mnt_dir, CTRL_NAME), 'rmtree', cmd)
# Invalidation is asynchronous...
try:
retry(5, lambda: not os.path.exists(fullname))
except RetryTimeoutError:
pass # assert_raises should fail
assert_raises(FileNotFoundError, os.stat, fullname)
assert dirname not in pyfuse3.listdir(self.mnt_dir)
async def test_getxattr(ctx):
(fh, inode) = await ctx.server.create(ROOT_INODE, newname(ctx),
file_mode(), os.O_RDWR, some_ctx)
await ctx.server.release(fh)
with assert_raises(FUSEError):
await ctx.server.getxattr(inode.st_ino, b'nonexistant-attr', some_ctx)
await ctx.server.setxattr(inode.st_ino, b'my-attr', b'strabumm!', some_ctx)
assert await ctx.server.getxattr(inode.st_ino, b'my-attr', some_ctx) == b'strabumm!'
await ctx.server.forget([(inode.st_ino, 1)])
await fsck(ctx)
await ctx.server.release(fh)
# Create
with assert_raises(FUSEError) as cm:
ctx.server._create(inode2.st_ino, b'dir1', dir_mode(), os.O_RDWR, some_ctx)
assert cm.value.errno == errno.EPERM
# Setattr
attr = await ctx.server.getattr(inode2a.st_ino, some_ctx)
with assert_raises(FUSEError) as cm:
await ctx.server.setattr(inode2a.st_ino, attr, SetattrFields(update_mtime=True),
None, some_ctx)
assert cm.value.errno == errno.EPERM
# xattr
with assert_raises(FUSEError) as cm:
await ctx.server.setxattr(inode2.st_ino, b'name', b'value', some_ctx)
assert cm.value.errno == errno.EPERM
with assert_raises(FUSEError) as cm:
await ctx.server.removexattr(inode2.st_ino, b'name', some_ctx)
assert cm.value.errno == errno.EPERM
await ctx.server.forget(list(ctx.server.open_inodes.items()))
await fsck(ctx)
def tst_mkdir(self):
dirname = self.newname()
fullname = self.mnt_dir + "/" + dirname
os.mkdir(fullname)
fstat = os.stat(fullname)
assert stat.S_ISDIR(fstat.st_mode)
assert pyfuse3.listdir(fullname) == []
assert fstat.st_nlink == 1
assert dirname in pyfuse3.listdir(self.mnt_dir)
os.rmdir(fullname)
assert_raises(FileNotFoundError, os.stat, fullname)
assert dirname not in pyfuse3.listdir(self.mnt_dir)
def tst_link(self):
name1 = os.path.join(self.mnt_dir, self.newname())
name2 = os.path.join(self.mnt_dir, self.newname())
src = self.src
shutil.copyfile(src, name1)
assert filecmp.cmp(name1, src, False)
os.link(name1, name2)
fstat1 = os.lstat(name1)
fstat2 = os.lstat(name2)
assert fstat1 == fstat2
assert fstat1.st_nlink == 2
assert basename(name2) in pyfuse3.listdir(self.mnt_dir)
assert filecmp.cmp(name1, name2, False)
os.unlink(name2)
fstat1 = os.lstat(name1)
assert fstat1.st_nlink == 1
os.unlink(name1)
def tst_readdir(self):
dir_ = os.path.join(self.mnt_dir, self.newname())
file_ = dir_ + "/" + self.newname()
subdir = dir_ + "/" + self.newname()
subfile = subdir + "/" + self.newname()
src = self.src
os.mkdir(dir_)
shutil.copyfile(src, file_)
os.mkdir(subdir)
shutil.copyfile(src, subfile)
listdir_is = pyfuse3.listdir(dir_)
listdir_is.sort()
listdir_should = [ basename(file_), basename(subdir) ]
listdir_should.sort()
assert listdir_is == listdir_should
os.unlink(file_)
os.unlink(subfile)
os.rmdir(subdir)
os.rmdir(dir_)
def tst_symlink(self):
linkname = self.newname()
fullname = self.mnt_dir + "/" + linkname
os.symlink("/imaginary/dest", fullname)
fstat = os.lstat(fullname)
assert stat.S_ISLNK(fstat.st_mode)
assert os.readlink(fullname) == "/imaginary/dest"
assert fstat.st_nlink == 1
assert linkname in pyfuse3.listdir(self.mnt_dir)
os.unlink(fullname)
assert_raises(FileNotFoundError, os.lstat, fullname)
assert linkname not in pyfuse3.listdir(self.mnt_dir)
# Try to delete
assert_raises(PermissionError, os.unlink, filename)
# Try to write
with pytest.raises(PermissionError):
open(filename, 'w+').write('Hello')
# delete properly
try:
s3ql.remove.main([tempdir])
except:
sys.excepthook(*sys.exc_info())
pytest.fail("s3qlrm raised exception")
assert 'lock_dir' not in pyfuse3.listdir(self.mnt_dir)