diff options
Diffstat (limited to 'repofs.py')
-rwxr-xr-x | repofs.py | 41 |
1 files changed, 25 insertions, 16 deletions
@@ -27,9 +27,6 @@ import bz2, gzip import yum.repoMDObject -FILEMODE = S_IRUSR|S_IRGRP|S_IROTH -DIRMODE = FILEMODE|S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH - def bunzip(infile,outfile): (p,f) = os.path.split(outfile) if not os.path.isdir(p): @@ -158,6 +155,18 @@ class SimpleYumRepo(object): cpio.stdin.close() cpio.wait() +class FileStat(fuse.Stat): + def __init__(self, **kw): + fuse.Stat.__init__(self, **kw) + self.st_mode = S_IFREG|S_IRUSR|S_IRGRP|S_IROTH + self.st_nlink = 1 + +class DirStat(fuse.Stat): + def __init__(self, **kw): + fuse.Stat.__init__(self, **kw) + self.st_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH + self.st_nlink = 2 + class FuseRO(Fuse): '''A Fuse subclass for implementing readonly filesystems.''' # chmod chown create link mkdir mknod rename rmdir setxattr(?) symlink @@ -171,7 +180,7 @@ class FuseRO(Fuse): mkdir = __rofs rename = __rofs rmdir = __rofs - setxattr = __rofs # You might override this so you can store xattrs + setxattr = __rofs symlink = __rofs truncate = __rofs unlink = __rofs @@ -238,22 +247,16 @@ class Repofs(FuseRO): def getattr(self, path): self.log("getattr('%s')" % path) - attr = fuse.Stat() - attr.st_mode = None - attr.st_nlink = 2 # sure, why not if (path == '/'): - attr.st_mode = DIRMODE - return attr + return DirStat() (packageuid, path) = self._splitpath(path) for repo in self.repos: for (f,t) in repo.files_for_package(packageuid): if f == path: - # found it! set mode to -r--r--r-- - attr.st_mode = FILEMODE - if t == 'd': # change mode to dr-xr-xr-x - attr.st_mode = DIRMODE - # TODO: set some more attributes - return attr + if t == 'f': + return FileStat() + elif t == 'd': + return DirStat() #raise OSError(errno.ENOENT, "No such file or directory") # SourceForge FUSE Python reference says to use this instead: return -errno.ENOENT @@ -298,7 +301,6 @@ class Repofs(FuseRO): def main(self, *a, **kw): return Fuse.main(self, *a, **kw) - def main(): usage = 'Repofs: mount a package repo and export all the files in the packages.\n\n' + Fuse.fusage server = Repofs(version="%prog " + fuse.__version__, usage=usage, @@ -312,3 +314,10 @@ def main(): if __name__ == '__main__': main() + +def will_test_setup(): + r = Repofs() + r.repopath="/tmp/test-repofs/repo" + r.cachedir="/tmp/test-repofs/cache" + r.fsinit() + return r |