diff install-static @ 50:ccd52fb45cff draft

Fix some bugs.
author David Barts <n5jrn@me.com>
date Thu, 30 May 2019 21:55:26 -0700
parents 15f665a620a2
children caed7c5e8318
line wrap: on
line diff
--- a/install-static	Thu May 30 21:44:26 2019 -0700
+++ b/install-static	Thu May 30 21:55:26 2019 -0700
@@ -34,7 +34,15 @@
         spath = os.path.join(source, entry)
         tpath = os.path.join(target, entry)
         stype = os.stat(spath).st_mode
+        try:
+            ttype = os.stat(tpath).st_mode
+        except FileNotFoundError:
+            ttype = None
         if S_ISREG(stype):
+            if ttype is not None and not S_ISREG(ttype):
+                sys.stderr.write(
+                    "{0}: {1!r} not a file\n".format(MYNAME, tpath))
+                sys.exit(1)
             if args.move:
                 print("mv", repr(spath), repr(tpath))
                 shutil.move(spath, tpath)
@@ -42,7 +50,11 @@
                 print("cp", repr(spath), repr(tpath))
                 copyfile(spath, tpath)
         elif S_ISDIR(stype):
-            if not os.path.isdir(tpath):
+            if ttype is not None and not S_ISDIR(ttype):
+                sys.stderr.write(
+                    "{0}: {1!r} not a directory\n".format(MYNAME, tpath))
+                sys.exit(1)
+            if not S_ISDIR(ttype):
                 print("mkdir", repr(tpath))
                 os.mkdir(tpath)
             copydir(spath, tpath, False)