Exemplo n.º 1
0
 def _encode_linux_xattr(self):
     if self.linux_xattr:
         result = vint.pack("V", len(self.linux_xattr))
         for name, value in self.linux_xattr:
             result += vint.pack("ss", name, value)
         return result
     else:
         return None
Exemplo n.º 2
0
 def _encode_posix1e_acl(self):
     # Encode as two strings (w/default ACL string possibly empty).
     if self.posix1e_acl:
         acls = self.posix1e_acl
         if len(acls) == 2:
             acls.extend(["", ""])
         return vint.pack("ssss", acls[0], acls[1], acls[2], acls[3])
     else:
         return None
Exemplo n.º 3
0
 def _encode_posix1e_acl(self):
     # Encode as two strings (w/default ACL string possibly empty).
     if self.posix1e_acl:
         acls = self.posix1e_acl
         txt_flags = posix1e.TEXT_ABBREVIATE
         num_flags = posix1e.TEXT_ABBREVIATE | posix1e.TEXT_NUMERIC_IDS
         acl_reps = [acls[0].to_any_text("", "\n", txt_flags), acls[1].to_any_text("", "\n", num_flags)]
         if len(acls) < 3:
             acl_reps += ["", ""]
         else:
             acl_reps.append(acls[2].to_any_text("", "\n", txt_flags))
             acl_reps.append(acls[3].to_any_text("", "\n", num_flags))
         return vint.pack("ssss", acl_reps[0], acl_reps[1], acl_reps[2], acl_reps[3])
     else:
         return None
Exemplo n.º 4
0
def path_info(conn, junk):
    _init_session()
    n = vint.read_vuint(conn)
    paths = []
    for i in range(n):
        paths.append(vint.read_bvec(conn))
    result = vfs.path_info(paths, vfs.RefList(None))
    assert(len(result) == len(paths))
    for item in result:
        if item:
            name, id, type = item
            vint.write_bvec(conn, vint.pack('sss', name, id, type))
        else:
            vint.write_bvec(conn, '')
    conn.ok()
Exemplo n.º 5
0
 def _encode_common(self):
     atime = self.atime.to_timespec()
     mtime = self.mtime.to_timespec()
     ctime = self.ctime.to_timespec()
     result = vint.pack('VVsVsVvVvVvV',
                        self.mode,
                        self.uid,
                        self.owner,
                        self.gid,
                        self.group,
                        self.rdev,
                        atime[0],
                        atime[1],
                        mtime[0],
                        mtime[1],
                        ctime[0],
                        ctime[1])
     return result
Exemplo n.º 6
0
 def _encode_common(self):
     atime = xstat.nsecs_to_timespec(self.atime)
     mtime = xstat.nsecs_to_timespec(self.mtime)
     ctime = xstat.nsecs_to_timespec(self.ctime)
     result = vint.pack('VVsVsVvVvVvV',
                        self.mode,
                        self.uid,
                        self.user,
                        self.gid,
                        self.group,
                        self.rdev,
                        atime[0],
                        atime[1],
                        mtime[0],
                        mtime[1],
                        ctime[0],
                        ctime[1])
     return result
Exemplo n.º 7
0
 def _encode_common(self):
     if not self.mode:
         return None
     atime = xstat.nsecs_to_timespec(self.atime)
     mtime = xstat.nsecs_to_timespec(self.mtime)
     ctime = xstat.nsecs_to_timespec(self.ctime)
     result = vint.pack('VVsVsVvVvVvV',
                        self.mode,
                        self.uid,
                        self.user,
                        self.gid,
                        self.group,
                        self.rdev,
                        atime[0],
                        atime[1],
                        mtime[0],
                        mtime[1],
                        ctime[0],
                        ctime[1])
     return result
Exemplo n.º 8
0
 def _encode_common(self):
     if not self.mode:
         return None
     atime = xstat.nsecs_to_timespec(self.atime)
     mtime = xstat.nsecs_to_timespec(self.mtime)
     ctime = xstat.nsecs_to_timespec(self.ctime)
     result = vint.pack('vvsvsvvVvVvVv',
                        self.mode,
                        self.uid,
                        self.user,
                        self.gid,
                        self.group,
                        self.rdev,
                        atime[0],
                        atime[1],
                        mtime[0],
                        mtime[1],
                        ctime[0],
                        ctime[1],
                        self.size if self.size is not None else -1)
     return result
Exemplo n.º 9
0
 def _encode_common(self):
     if not self.mode:
         return None
     atime = xstat.nsecs_to_timespec(self.atime)
     mtime = xstat.nsecs_to_timespec(self.mtime)
     ctime = xstat.nsecs_to_timespec(self.ctime)
     result = vint.pack(
         "vvsvsvvVvVvV",
         self.mode,
         self.uid,
         self.user,
         self.gid,
         self.group,
         self.rdev,
         atime[0],
         atime[1],
         mtime[0],
         mtime[1],
         ctime[0],
         ctime[1],
     )
     return result
Exemplo n.º 10
0
 def _encode_linux_attr(self):
     if self.linux_attr:
         return vint.pack("V", self.linux_attr)
     else:
         return None
Exemplo n.º 11
0
 def _encode_path(self):
     if self.path:
         return vint.pack("s", self.path)
     else:
         return None
Exemplo n.º 12
0
    import libnacl.sealed
except ImportError:
    libnacl = None

from bup import compat, git, vfs
from bup.helpers import mkdirp
from bup.vint import read_vuint, pack
from bup.storage import get_storage, FileNotFound, Kind
from bup.compat import bytes_from_uint, byte_int
from bup.repo import ConfigRepo
from bup import hashsplit

# 1 GiB is the most we're willing to store as a single object
# (this is after compression and encryption)
MAX_ENC_BLOB = 1024 * 1024 * 1024
MAX_ENC_BLOB_VUINT_LEN = len(pack('V', MAX_ENC_BLOB))

NONCE_DATA, NONCE_LEN = 0, 0x80


class EncryptedVuintReader:
    def __init__(self, file, vuint_cs, szhint):
        self.file = file
        self.vuint_cs = [byte_int(x) for x in vuint_cs]
        self.offs = 0
        self.szhint = szhint

    def read(self, sz):
        assert sz == 1
        v = byte_int(self.file.read(1, szhint=self.szhint)[0])
        self.szhint -= 1
Exemplo n.º 13
0
 def _encode_linux_attr(self):
     if self.linux_attr:
         return vint.pack('V', self.linux_attr)
     else:
         return None
Exemplo n.º 14
0
 def _encode_path(self):
     if self.path:
         return vint.pack('s', self.path)
     else:
         return None
Exemplo n.º 15
0
def pack_and_unpack(types, *values):
    data = vint.pack(types, *values)
    return vint.unpack(types, data)
Exemplo n.º 16
0
def pack_and_unpack(types, *values):
    data = vint.pack(types, *values)
    return vint.unpack(types, data)