~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/common/zip.py

  • Committer: mattgiuca
  • Date: 2008-06-13 09:13:30 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:763
Zip file uploading now works.
(Patch submitted by wagrant, modified and approved by mgiuca).

2 bugs fixed: Paths were being created as filesystem-relative which should
have been jail-relative. Zip was being passed the string contents of the file,
when it should have been passed the file object.

common/zip.py: Now accepts an absolute path, not a URL path.
    (Doesn't munge the path).
    This is so it can be called from inside or outside the jail;
    the caller decides which filesystem it is relative to.
fileservice_lib/action.py:
    1. Now passes the absolute path within the jail.
    2. Now passes the field "file" not "data" (file object, not string).
        Static Typing: Sometimes It Is Good

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
    Note: All files go directly into the path. To avoid having a "zip bomb"
92
92
    situation, the zip file should have a single directory in it with all the
93
93
    files.
 
94
    The path is an absolute path in the current filesystem
 
95
    (if this code is executed inside the jail, then it's inside the jail,
 
96
    if it's not then it's not).
94
97
    """
95
98
    zip = zipfile.ZipFile(file, 'r')
96
99
    # First test the zip file
98
101
        raise OSError("ZIP: Bad zip file")
99
102
 
100
103
    for filename in zip.namelist():
101
 
        # Work out the name of this file on the local file system, and make
102
 
        # sure it is valid
103
 
        relpath = os.path.join(path, filename)
104
 
        _, localpath = studpath.url_to_local(relpath)
105
 
        if localpath is None:
106
 
            raise OSError("ZIP: Permission denied")
 
104
        localpath = os.path.join(path, filename)
107
105
        # Create directory for filename
108
106
        (file_dir, _) = os.path.split(localpath)
109
107
        if not os.path.exists(file_dir):