]> git.phdru.name Git - dotfiles.git/blobdiff - bin/unzip.py
Fix(.vim/python/virtualenv.py): Only activate venv for the current version
[dotfiles.git] / bin / unzip.py
index e88e5265a5504d69949ec375d348845424f33e1d..ab62d240cf83482892dbcd08a0437cf1aa997fb0 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python3
 """Unzip with encoded filenames
 
 #! /usr/bin/env python3
 """Unzip with encoded filenames
 
-   Written by Oleg Broytman. Copyright (C) 2009-2023 PhiloSoft Design.
+   Written by Oleg Broytman. Copyright (C) 2009-2024 PhiloSoft Design.
 """
 
 import sys, os, time
 """
 
 import sys, os, time
@@ -27,8 +27,7 @@ out = '.'
 for zinfo in zf.infolist():
     path = zinfo.filename
     if isinstance(path, bytes):
 for zinfo in zf.infolist():
     path = zinfo.filename
     if isinstance(path, bytes):
-        path = path.decode('cp866')
-        recoded_path = path.encode(default_encoding)
+        recoded_path = path.decode('cp866').encode(default_encoding)
     else:
         recoded_path = path
     print(recoded_path)
     else:
         recoded_path = path
     print(recoded_path)
@@ -43,10 +42,15 @@ for zinfo in zf.infolist():
 
     if not tgt.endswith('/'):
         infile = zf.open(zinfo.filename)
 
     if not tgt.endswith('/'):
         infile = zf.open(zinfo.filename)
-        fp = open(tgt, 'wb')
-        copyfileobj(infile, fp)
-        fp.close()
+        if zinfo.external_attr == 0xA1ED0000:
+            os.symlink(infile.read(), tgt)
+        else:  # regular file
+            fp = open(tgt, 'wb')
+            copyfileobj(infile, fp)
+            fp.close()
         infile.close()
         infile.close()
-    dt = time.mktime(zinfo.date_time + (0, 0, -1))
-    os.utime(tgt, (dt, dt))
+    if zinfo.external_attr != 0xA1ED0000:
+        # set timestamp for directories and files but not symlinks
+        dt = time.mktime(zinfo.date_time + (0, 0, -1))
+        os.utime(tgt, (dt, dt))
 zf.close()
 zf.close()