2015-10-01 21:40:10 +00:00
|
|
|
|
|
|
|
import re
|
|
|
|
import os.path
|
|
|
|
|
2015-10-22 13:28:26 +00:00
|
|
|
from allmydata.util.assertutil import precondition, _assert
|
2015-10-01 21:40:10 +00:00
|
|
|
|
|
|
|
def path2magic(path):
|
|
|
|
return re.sub(ur'[/@]', lambda m: {u'/': u'@_', u'@': u'@@'}[m.group(0)], path)
|
|
|
|
|
|
|
|
def magic2path(path):
|
|
|
|
return re.sub(ur'@[_@]', lambda m: {u'@_': u'/', u'@@': u'@'}[m.group(0)], path)
|
|
|
|
|
|
|
|
|
|
|
|
IGNORE_SUFFIXES = [u'.backup', u'.tmp', u'.conflicted']
|
|
|
|
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 13:28:26 +00:00
|
|
|
|
2015-10-01 21:40:10 +00:00
|
|
|
while path_u != u"":
|
2015-10-22 13:28:26 +00:00
|
|
|
oldpath_u = path_u
|
2015-10-01 21:40:10 +00:00
|
|
|
path_u, tail_u = os.path.split(path_u)
|
|
|
|
if tail_u.startswith(u"."):
|
|
|
|
return True
|
2015-10-22 13:28:26 +00: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 21:40:10 +00:00
|
|
|
return False
|