解压缩创建目录

时间:2016-03-15 19:58:13

标签: python linux bash compression unzip

unzip -o my_file_name.esb.zip

结果

Archive:  my_file_name.esb.zip
  inflating: my_file_name.esb  
checkdir error:  my_file_name.esb exists but is not directory
                 unable to process my_file_name.esb/.

仅适用于此特定文件。执行该命令后,ls显示已解除my_file_name.esb,但转为空目录。它也是一个二进制文件,这是我期望的那种文件。

提取文件后重复命令有时会产生:

Archive: my_file_name.esb.zip
error: cannot delete old my_file_name.esb
       Is a directory

我很困惑为什么这个文件既作为文件又作为目录。它会导致运行解压缩的Python脚本出错,从而阻止它继续运行。

在Python中:

from sh import gunzip
unzip('-o',myfile)

其中myfile是.zip存档的路径。

Python在此处停止:

sh.py(187):         if self.stderr is None:
sh.py(190):             exc_stderr = self.stderr[:self.truncate_cap]
sh.py(191):             err_delta = len(self.stderr) - len(exc_stderr)
sh.py(192):             if err_delta:
sh.py(195):         msg = "\n\n  RAN: %r\n\n  STDOUT:\n%s\n\n  STDERR:\n%s" % \
sh.py(196):             (full_cmd, exc_stdout.decode(DEFAULT_ENCODING, "replace"),
 --- modulename: utf_8, funcname: decode
utf_8.py(16):     return codecs.utf_8_decode(input, errors, True)
sh.py(197):              exc_stderr.decode(DEFAULT_ENCODING, "replace"))
 --- modulename: utf_8, funcname: decode
utf_8.py(16):     return codecs.utf_8_decode(input, errors, True)
sh.py(198):         super(ErrorReturnCode, self).__init__(msg)
 --- modulename: trace, funcname: _unsettrace
trace.py(80):         sys.settrace(None)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/trace.py", line 819, in <module>
    main()
  File "/usr/lib/python2.7/trace.py", line 807, in main
    t.runctx(code, globs, globs)
  File "/usr/lib/python2.7/trace.py", line 513, in runctx
    exec cmd in globals, locals
  File "importItAll.py", line 40, in <module>
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1021, in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 486, in __init__
    self.wait()
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 500, in wait
    self.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 516, in handle_command_exit_code
    raise exc(self.ran, self.process.stdout, self.process.stderr)
sh.ErrorReturnCode_2: 

  RAN: '/usr/bin/unzip -o ./path/to/my_file_name.esb.zip'

  STDOUT:
sh.py(1269):                 if stderr is OProc.STDOUT:
sh.py(1272):                     os.dup2(self._slave_stderr_fd, 2)
sh.py(1275):                 max_fd = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
sh.py(1276):                 os.closerange(3, max_fd)
sh.py(1280):                 if self.call_args["tty_out"]:
sh.py(1281):                     tmp_fd = os.open(os.ttyname(1), os.O_RDWR)
sh.py(1282):                     os.close(tmp_fd)
sh.py(1285):                 if self.call_args["tty_out"]:
sh.py(1286):                     setwinsize(1, self.call_args["tty_size"])
 --- modulename: sh, funcname: setwinsize
sh.py(1036):     rows, cols = rows_cols
sh.py(1037):     TIOCSWINSZ = getattr(termios, 'TIOCSWINSZ', -2146929561)
sh.py(1039):  ... (365 more, please see e.stdout)

  STDERR:
checkdir error:  my_file_name.esb exists but is not directory
                 unable to process my_file_name.esb/.

有什么建议吗?

使用Archive Manager,我发现zip文件包含:

Name                Size          Type         Modified
my_file_name.esb    0  bytes      Folder       17 February 2016, 12:40
my_file_name.esb    581.3 MB      unknown      16 February 2016, 13:45

0 个答案:

没有答案