summaryrefslogtreecommitdiff
path: root/usr/src/tools/scripts/git-pbchk.py
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2019-07-15 17:24:25 -0700
committerGarrett D'Amore <garrett@damore.org>2019-07-18 09:41:16 -0700
commit955eb5e1fb25fc64c2c34501c3d9426057e3b1f8 (patch)
treec5e63f7ed47c76dd9b88e2a5383a26ab0ed9124d /usr/src/tools/scripts/git-pbchk.py
parent4c6a557ef3ee09ce3af0b3773cf03d745a0bdcb6 (diff)
downloadillumos-joyent-955eb5e1fb25fc64c2c34501c3d9426057e3b1f8.tar.gz
10167 unable to check out illumos-gate on Windows
Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk> Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com> Reviewed by: Andrew Stormont <andyjstormont@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/tools/scripts/git-pbchk.py')
-rw-r--r--usr/src/tools/scripts/git-pbchk.py83
1 files changed, 77 insertions, 6 deletions
diff --git a/usr/src/tools/scripts/git-pbchk.py b/usr/src/tools/scripts/git-pbchk.py
index 559cf7e9e5..99bce29087 100644
--- a/usr/src/tools/scripts/git-pbchk.py
+++ b/usr/src/tools/scripts/git-pbchk.py
@@ -17,7 +17,7 @@
#
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2008, 2012 Richard Lowe
-# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+# Copyright 2019 Garrett D'Amore <garrett@damore.org>
# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
# Copyright 2016 Nexenta Systems, Inc.
# Copyright (c) 2019, Joyent, Inc.
@@ -175,11 +175,14 @@ def not_check(root, cmd):
os.path.join(root, "exception_lists", cmd)]))
return Ignore.ignore(root, ignorefiles)
-def gen_files(root, parent, paths, exclude):
+def gen_files(root, parent, paths, exclude, filter=None):
"""Return a function producing file names, relative to the current
directory, of any file changed on this branch (limited to 'paths' if
requested), and excluding files for which exclude returns a true value """
+ if filter is None:
+ filter = lambda x: os.path.isfile(x)
+
# Taken entirely from Python 2.6's os.path.relpath which we would use if we
# could.
def relpath(path, here):
@@ -204,11 +207,18 @@ def gen_files(root, parent, paths, exclude):
# will be caught by other invocations of git().
continue
empty = not res
- if (os.path.isfile(path) and not empty and
+ if (filter(path) and not empty and
select(path) and not exclude(abspath)):
yield path
return ret
+def gen_links(root, parent, paths, exclude):
+ """Return a function producing symbolic link names, relative to the current
+ directory, of any file changed on this branch (limited to 'paths' if
+ requested), and excluding files for which exclude returns a true value """
+
+ return gen_files(root, parent, paths, exclude, lambda x: os.path.islink(x))
+
def comchk(root, parent, flist, output):
output.write("Comments:\n")
@@ -300,7 +310,53 @@ def wscheck(root, parent, flist, output):
ret |= WsCheck.wscheck(fh, output=output)
return ret
-def run_checks(root, parent, cmds, paths='', opts={}):
+def symlinks(root, parent, flist, output):
+ ret = 0
+ output.write("Symbolic links:\n")
+ for f in flist():
+ output.write(" "+f+"\n")
+ ret |= 1
+ return ret
+
+def iswinreserved(name):
+ reserved = [
+ 'con', 'prn', 'aux', 'nul',
+ 'com1', 'com2', 'com3', 'com4', 'com5',
+ 'com6', 'com7', 'com8', 'com9', 'com0',
+ 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5',
+ 'lpt6', 'lpt7', 'lpt8', 'lpt9', 'lpt0' ]
+ l = name.lower()
+ for r in reserved:
+ if l == r or l.startswith(r+"."):
+ return True
+ return False
+
+def haswinspecial(name):
+ specials = '<>:"\\|?*'
+ for c in name:
+ if c in specials:
+ return True
+ return False
+
+def winnames(root, parent, flist, output):
+ ret = 0
+ output.write("Illegal filenames (Windows):\n")
+ for f in flist():
+ if haswinspecial(f):
+ output.write(" "+f+": invalid character in name\n")
+ ret |= 1
+ continue
+
+ parts = f.split('/')
+ for p in parts:
+ if iswinreserved(p):
+ output.write(" "+f+": reserved file name\n")
+ ret |= 1
+ break
+
+ return ret
+
+def run_checks(root, parent, cmds, scmds, paths='', opts={}):
"""Run the checks given in 'cmds', expected to have well-known signatures,
and report results for any which fail.
@@ -322,6 +378,17 @@ def run_checks(root, parent, cmds, paths='', opts={}):
if result != 0:
print(s.getvalue())
+ for cmd in scmds:
+ s = StringIO()
+
+ exclude = not_check(root, cmd.__name__)
+ result = cmd(root, parent, gen_links(root, parent, paths, exclude),
+ output=s)
+ ret |= result
+
+ if result != 0:
+ print(s.getvalue())
+
return ret
def nits(root, parent, paths):
@@ -332,8 +399,10 @@ def nits(root, parent, paths):
keywords,
manlint,
mapfilechk,
+ winnames,
wscheck]
- run_checks(root, parent, cmds, paths)
+ scmds = [symlinks]
+ run_checks(root, parent, cmds, scmds, paths)
def pbchk(root, parent, paths):
cmds = [comchk,
@@ -344,8 +413,10 @@ def pbchk(root, parent, paths):
keywords,
manlint,
mapfilechk,
+ winnames,
wscheck]
- run_checks(root, parent, cmds)
+ scmds = [symlinks]
+ run_checks(root, parent, cmds, scmds)
def main(cmd, args):
parent_branch = None