2015-10-01 22:40:10 +01:00
|
|
|
import re
|
|
|
|
import os.path
|
|
|
|
|
2015-10-22 14:28:26 +01:00
|
|
|
from allmydata.util.assertutil import precondition, _assert
|
2015-10-01 22:40:10 +01:00
|
|
|
|
|
|
|
def path2magic(path):
|
2019-04-25 11:18:33 +02:00
|
|
|
return re.sub(u'[/@]', lambda m: {u'/': u'@_', u'@': u'@@'}[m.group(0)], path)
|
2015-10-01 22:40:10 +01:00
|
|
|
|
|
|
|
def magic2path(path):
|
2019-04-25 11:18:33 +02:00
|
|
|
return re.sub(u'@[_@]', lambda m: {u'@_': u'/', u'@@': u'@'}[m.group(0)], path)
|
2015-10-01 22:40:10 +01:00
|
|
|
|
|
|
|
|
2016-04-11 22:22:11 -07:00
|
|
|
IGNORE_SUFFIXES = [u'.backup', u'.tmp', u'.conflict']
|
2015-10-01 22:40:10 +01:00
|
|
|
IGNORE_PREFIXES = [u'.']
|
|
|
|
|
|
|
|
def should_ignore_file(path_u):
|
|
|
|
precondition(isinstance(path_u, unicode), path_u=path_u)
|
|
|
|
|
|
|
|
for suffix in IGNORE_SUFFIXES:
|
|
|
|
if path_u.endswith(suffix):
|
|
|
|
return True
|
2015-10-22 14:28:26 +01:00
|
|
|
|
2015-10-01 22:40:10 +01:00
|
|
|
while path_u != u"":
|
2015-10-22 14:28:26 +01:00
|
|
|
oldpath_u = path_u
|
2015-10-01 22:40:10 +01:00
|
|
|
path_u, tail_u = os.path.split(path_u)
|
|
|
|
if tail_u.startswith(u"."):
|
|
|
|
return True
|
2015-10-22 14:28:26 +01:00
|
|
|
if path_u == oldpath_u:
|
|
|
|
return True # the path was absolute
|
|
|
|
_assert(len(path_u) < len(oldpath_u), path_u=path_u, oldpath_u=oldpath_u)
|
|
|
|
|
2015-10-01 22:40:10 +01:00
|
|
|
return False
|