1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
"""
Bareos specific Fuse node.
"""
from bareos.exceptions import *
from bareos.fuse.node.bvfscommon import BvfsCommon
from bareos.fuse.node.bvfsfile import BvfsFile
from bareos.fuse.node.directory import Directory
from dateutil import parser as DateParser
import errno
import logging
class BvfsDir(Directory, BvfsCommon):
def __init__(self, root, name, job, pathid, directory = None):
super(BvfsDir, self).__init__(root, name)
self.job = job
self.jobid = job.job['jobid']
self.pathid = pathid
self.static = True
self.directory = directory
if directory:
self.set_stat(directory['stat'])
BvfsCommon.init(self, self.root, self.jobid, self.directory['fullpath'], None, self.directory['stat'])
@classmethod
def get_id(cls, name, job, pathid, directory = None):
id = None
if pathid == None:
id = "jobid=%s" % (str(job.job['jobid']))
else:
id = "pathid=%s" % (str(pathid))
return id
def setxattr(self, path, key, value, flags):
if path.len() == 0:
if key == self.XattrKeyRestoreTrigger and value == "restore":
if not self.root.restoreclient:
self.logger.warning("no restoreclient given, files can not be restored")
return -errno.ENOENT
if not self.root.restorepath:
self.logger.warning("no restorepath given, files can not be restored")
return -errno.ENOENT
else:
self.restore(path, [ self.pathid ], None)
return super(BvfsDir, self).setxattr(path, key, value, flags)
def do_update(self):
directories = self.get_directories(self.pathid)
files = self.get_files(self.pathid)
for i in directories:
if i['name'] != "." and i['name'] != "..":
name = i['name'].rstrip('/')
pathid = i['pathid']
self.add_subnode(BvfsDir, name, self.job, pathid, i)
if self.directory:
for i in files:
self.add_subnode(BvfsFile, i, self.job, self.directory['fullpath'])
def get_directories(self, pathid):
if pathid == None:
self.bsock.call(".bvfs_update jobid=%s" % (self.jobid))
path = 'path=""'
else:
path = 'pathid=%s' % pathid
data = self.bsock.call('.bvfs_lsdirs jobid=%s %s' % (self.jobid, path))
directories = data['directories']
if pathid == None:
found = False
for i in directories:
if i['name'] != "." and i['name'] != "..":
if i['name'] == "/":
self.directory = i
self.pathid = i['pathid']
BvfsCommon.init(self, self.root, self.jobid, i['fullpath'], None, i['stat'])
else:
found = True
if not found:
# skip empty root directory
if not self.pathid:
# no pathid and no directoies found. This should not happen
return []
return self.get_directories(self.pathid)
return directories
def get_files(self, pathid):
if pathid:
data = self.bsock.call(".bvfs_lsfiles jobid=%s pathid=%s" % (self.jobid, pathid))
return data['files']
else:
return []
|