diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-02-23 19:26:15 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-02-23 19:26:15 +0000 |
commit | 3723aceece805e764c93c8fe11f3fb0663496f7b (patch) | |
tree | 30d10f8731b0e36720a8d71e4cf0ebc64647de3f /obnamlib/plugins/fuse_plugin.py | |
parent | 37ef8262c70d4496366e6e65e5ca71c0a7c17bca (diff) | |
download | obnam-3723aceece805e764c93c8fe11f3fb0663496f7b.tar.gz |
Move multiple_root_list into init_root, rename variables
Diffstat (limited to 'obnamlib/plugins/fuse_plugin.py')
-rw-r--r-- | obnamlib/plugins/fuse_plugin.py | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/obnamlib/plugins/fuse_plugin.py b/obnamlib/plugins/fuse_plugin.py index dc85e87f..5a073ec6 100644 --- a/obnamlib/plugins/fuse_plugin.py +++ b/obnamlib/plugins/fuse_plugin.py @@ -201,8 +201,6 @@ class ObnamFuse(fuse.Fuse): self.obnam = kw['obnam'] ObnamFuseFile.fs = self self.file_class = ObnamFuseFile - self.rootlist = None - self.rootstat = None self.init_root() fuse.Fuse.__init__(self, *args, **kw) @@ -211,8 +209,45 @@ class ObnamFuse(fuse.Fuse): generations = [gen for gen in self.obnam.repo.list_generations() if not self.obnam.repo.get_is_checkpoint(gen)] - self.rootstat, self.rootlist = self.multiple_root_list(generations) - tracing.trace('multiple rootlist=%r', self.rootlist) + # self.rootlist holds the stat information for each entry at + # the root of the FUSE filesystem: /.pid, /latest, and one for + # each generation. + self.rootlist = {} + + used_generations = [] + for gen in generations: + path = '/' + str(gen) + try: + genstat = self.get_stat_in_generation(path) + start, end = self.obnam.repo.get_generation_times(gen) + genstat.st_ctime = genstat.st_mtime = end + self.rootlist[path] = genstat + used_generations.append(gen) + except obnamlib.Error: + pass + + assert used_generations + + # self.rootstat is the stat information for the root of the + # FUSE filesystem. We set it to the same as that of the latest + # generation. + latest_gen_id = used_generations[-1] + latest_gen_root_stat = self.rootlist['/' + str(latest_gen_id)] + self.rootstat = fuse.Stat(**latest_gen_root_stat.__dict__) + + # Add an entry for /latest to self.rootlist. + symlink_stat = fuse.Stat( + target=str(latest_gen_id), + **latest_gen_root_stat.__dict__) + symlink_stat.st_mode &= ~(stat.S_IFDIR | stat.S_IFREG) + symlink_stat.st_mode |= stat.S_IFLNK + self.rootlist['/latest'] = symlink_stat + + # Add an entry for /.pid to self.rootlist. + pidstat = fuse.Stat(**self.rootstat.__dict__) + pidstat.st_mode = ( + stat.S_IFREG | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) + self.rootlist['/.pid'] = pidstat def root_refresh(self): tracing.trace('called') @@ -247,38 +282,6 @@ class ObnamFuse(fuse.Fuse): st.st_ctime = st.st_mtime return st - def multiple_root_list(self, generations): - rootlist = {} - used_generations = [] - for gen in generations: - path = '/' + str(gen) - try: - genstat = self.get_stat_in_generation(path) - start, end = self.obnam.repo.get_generation_times(gen) - genstat.st_ctime = genstat.st_mtime = end - rootlist[path] = genstat - used_generations.append(gen) - except obnamlib.Error: - pass - - assert used_generations - - latest = used_generations[-1] - laststat = rootlist['/' + str(latest)] - rootstat = fuse.Stat(**laststat.__dict__) - - laststat = fuse.Stat(target=str(latest), **laststat.__dict__) - laststat.st_mode &= ~(stat.S_IFDIR | stat.S_IFREG) - laststat.st_mode |= stat.S_IFLNK - rootlist['/latest'] = laststat - - pidstat = fuse.Stat(**rootstat.__dict__) - pidstat.st_mode = ( - stat.S_IFREG | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) - rootlist['/.pid'] = pidstat - - return (rootstat, rootlist) - def get_gen_path(self, path): if path.count('/') == 1: gen = path[1:] |