~hazmat/pyjuju/zk-log-client-disable

« back to all changes in this revision

Viewing changes to juju/charm/bundle.py

  • Committer: William Reade
  • Author(s): William Reade
  • Date: 2012-04-04 12:29:56 UTC
  • mfrom: (510.1.3 fix-charm-symlinks)
  • Revision ID: fwereade@gmail.com-20120404122956-ew1xusf09udwc0fm
When extracting charms, use only filetype mode bits to detect symlinkicity

We had been writing, and checking for, a magic value (in external_attr)
which happened to equal `(stat.S_IFLNK | 0755) << 16`; the charm store was
giving us one equal to `(stat.S_IFLNK | 0777) << 16`, and we weren't
considering that to be a symlink. We now just check the filetype and ignore
permissions on symlinks.

R=hazmat
CC=
https://codereview.appspot.com/5980045

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import hashlib
2
2
import tempfile
3
3
import os
 
4
import stat
4
5
 
5
6
from zipfile import ZipFile, BadZipfile
6
7
 
7
 
from juju.charm.base import CharmBase, get_revision, ZIP_SYMLINK_ATTR
 
8
from juju.charm.base import CharmBase, get_revision
8
9
from juju.charm.config import ConfigOptions
9
10
from juju.charm.metadata import MetaData
10
11
from juju.errors import CharmError
58
59
        from .directory import CharmDirectory
59
60
        zf = ZipFile(self.path, "r")
60
61
        for info in zf.infolist():
61
 
            # Extract symlinks, see base.py comments on constant.
62
 
            if info.external_attr == ZIP_SYMLINK_ATTR:
 
62
            mode = info.external_attr >> 16
 
63
            if stat.S_ISLNK(mode):
63
64
                source = zf.read(info.filename)
64
65
                target = os.path.join(directory_path, info.filename)
65
66
                # Support extracting over existing charm.
70
71
                continue
71
72
 
72
73
            # Preserve mode
73
 
            mode = info.external_attr >> 16
74
74
            extract_path = zf.extract(info, directory_path)
75
75
            os.chmod(extract_path, mode)
76
76
        return CharmDirectory(directory_path)