X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbup%2Fhelpers.py;h=581a4bb3827465ab983f7afe4ba1602b44357870;hb=b7699bfac2031b01fb5b40001d874b94de87d1fc;hp=b052b63021511b035a94ac9945e01dce1099637d;hpb=d926749abdfe849117bf95c721d6f1858fef1d12;p=bup.git diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index b052b63..581a4bb 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -1079,3 +1079,22 @@ else: return time.strftime('%z', localtime(t)) def to_py_time(x): return x + + +_some_invalid_save_parts_rx = re.compile(r'[[ ~^:?*\\]|\.\.|//|@{') + +def valid_save_name(name): + # Enforce a superset of the restrictions in git-check-ref-format(1) + if name == '@' \ + or name.startswith('/') or name.endswith('/') \ + or name.endswith('.'): + return False + if _some_invalid_save_parts_rx.search(name): + return False + for c in name: + if ord(c) < 0x20 or ord(c) == 0x7f: + return False + for part in name.split('/'): + if part.startswith('.') or part.endswith('.lock'): + return False + return True