mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 09:19:31 +00:00
Auto ignore darc cache and store directories when creating archives
This commit is contained in:
parent
9f949241b0
commit
d15d57b268
3 changed files with 49 additions and 5 deletions
|
@ -9,7 +9,7 @@
|
||||||
from .cache import Cache
|
from .cache import Cache
|
||||||
from .keychain import Keychain
|
from .keychain import Keychain
|
||||||
from .helpers import location_validator, format_file_size, format_time,\
|
from .helpers import location_validator, format_file_size, format_time,\
|
||||||
format_file_mode, walk_dir, IncludePattern, ExcludePattern, exclude_path
|
format_file_mode, walk_path, IncludePattern, ExcludePattern, exclude_path
|
||||||
|
|
||||||
|
|
||||||
class Archiver(object):
|
class Archiver(object):
|
||||||
|
@ -53,8 +53,22 @@ def do_create(self, args):
|
||||||
return self.exit_code
|
return self.exit_code
|
||||||
archive = Archive(store, keychain)
|
archive = Archive(store, keychain)
|
||||||
cache = Cache(store, keychain)
|
cache = Cache(store, keychain)
|
||||||
|
# Add darc cache dir to inode_skip list
|
||||||
|
skip_inodes = []
|
||||||
|
try:
|
||||||
|
st = os.stat(Cache.cache_dir_path())
|
||||||
|
skip_inodes.append((st.st_ino, st.st_dev))
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
# Add local store dir to inode_skip list
|
||||||
|
if not args.archive.host:
|
||||||
|
try:
|
||||||
|
st = os.stat(args.archive.path)
|
||||||
|
skip_inodes.append((st.st_ino, st.st_dev))
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
for path in args.paths:
|
for path in args.paths:
|
||||||
for path, st in walk_dir(unicode(path)):
|
for path, st in walk_path(unicode(path)):
|
||||||
if exclude_path(path, args.patterns):
|
if exclude_path(path, args.patterns):
|
||||||
continue
|
continue
|
||||||
self.print_verbose(path)
|
self.print_verbose(path)
|
||||||
|
|
|
@ -11,13 +11,18 @@ class Cache(object):
|
||||||
def __init__(self, store, keychain):
|
def __init__(self, store, keychain):
|
||||||
self.store = store
|
self.store = store
|
||||||
self.keychain = keychain
|
self.keychain = keychain
|
||||||
self.path = os.path.join(os.path.expanduser('~'), '.darc', 'cache',
|
self.path = os.path.join(Cache.cache_dir_path(),
|
||||||
'%s.cache' % self.store.id.encode('hex'))
|
'%s.cache' % self.store.id.encode('hex'))
|
||||||
self.tid = -1
|
self.tid = -1
|
||||||
self.open()
|
self.open()
|
||||||
if self.tid != self.store.tid:
|
if self.tid != self.store.tid:
|
||||||
self.init()
|
self.init()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def cache_dir_path():
|
||||||
|
"""Return path to directory used for storing users cache files"""
|
||||||
|
return os.path.join(os.path.expanduser('~'), '.darc', 'cache')
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
if not os.path.exists(self.path):
|
if not os.path.exists(self.path):
|
||||||
return
|
return
|
||||||
|
|
|
@ -8,6 +8,29 @@
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
|
|
||||||
|
def encode_long(v):
|
||||||
|
bytes = []
|
||||||
|
while True:
|
||||||
|
if v > 0x7f:
|
||||||
|
bytes.append(0x80 | (v % 0x80))
|
||||||
|
v >>= 7
|
||||||
|
else:
|
||||||
|
bytes.append(v)
|
||||||
|
return ''.join(chr(x) for x in bytes)
|
||||||
|
|
||||||
|
|
||||||
|
def decode_long(bytes):
|
||||||
|
v = 0
|
||||||
|
base = 0
|
||||||
|
for x in bytes:
|
||||||
|
b = ord(x)
|
||||||
|
if b & 0x80:
|
||||||
|
v += (b & 0x7f) << base
|
||||||
|
base += 7
|
||||||
|
else:
|
||||||
|
return v + (b << base)
|
||||||
|
|
||||||
|
|
||||||
def zero_pad(data, length):
|
def zero_pad(data, length):
|
||||||
"""Make sure data is `length` bytes long by prepending zero bytes
|
"""Make sure data is `length` bytes long by prepending zero bytes
|
||||||
|
|
||||||
|
@ -63,12 +86,14 @@ class ExcludePattern(IncludePattern):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def walk_dir(path):
|
def walk_path(path, skip_inodes=None):
|
||||||
st = os.lstat(path)
|
st = os.lstat(path)
|
||||||
|
if skip_inodes and (st.st_ino, st.st_dev) in skip_inodes:
|
||||||
|
return
|
||||||
yield path, st
|
yield path, st
|
||||||
if stat.S_ISDIR(st.st_mode):
|
if stat.S_ISDIR(st.st_mode):
|
||||||
for f in os.listdir(path):
|
for f in os.listdir(path):
|
||||||
for x in walk_dir(os.path.join(path, f)):
|
for x in walk_path(os.path.join(path, f), skip_inodes):
|
||||||
yield x
|
yield x
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue