LEFT | RIGHT |
(no file at all) | |
1 import os | 1 import os |
2 import hashlib | 2 import hashlib |
3 import inspect | 3 import inspect |
4 import shutil | 4 import shutil |
| 5 import stat |
5 import yaml | 6 import yaml |
6 import zipfile | 7 import zipfile |
7 | 8 |
8 from juju.lib.testing import TestCase | 9 from juju.lib.testing import TestCase |
9 from juju.lib.filehash import compute_file_hash | 10 from juju.lib.filehash import compute_file_hash |
10 from juju.charm.metadata import MetaData | 11 from juju.charm.metadata import MetaData |
11 from juju.charm.bundle import CharmBundle | 12 from juju.charm.bundle import CharmBundle |
12 from juju.errors import CharmError | 13 from juju.errors import CharmError |
13 from juju.charm.directory import CharmDirectory | 14 from juju.charm.directory import CharmDirectory |
14 from juju.charm.provider import get_charm_from_path | 15 from juju.charm.provider import get_charm_from_path |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 189 |
189 # Verify we can extract it over again | 190 # Verify we can extract it over again |
190 os.remove(sym_path) | 191 os.remove(sym_path) |
191 os.symlink('./config.yaml', sym_path) | 192 os.symlink('./config.yaml', sym_path) |
192 charm_dir = CharmDirectory(charm_path) | 193 charm_dir = CharmDirectory(charm_path) |
193 bundle = charm_dir.as_bundle() | 194 bundle = charm_dir.as_bundle() |
194 bundle.extract_to(extract_dir) | 195 bundle.extract_to(extract_dir) |
195 self.assertEqual(os.readlink(os.path.join(extract_dir, 'foobar')), | 196 self.assertEqual(os.readlink(os.path.join(extract_dir, 'foobar')), |
196 './config.yaml') | 197 './config.yaml') |
197 | 198 |
| 199 def test_extract_symlink_mode(self): |
| 200 # lp:973260 - charms packed by different tools that record symlink |
| 201 # mode permissions differently (ie the charm store) don't extract |
| 202 # correctly. |
| 203 charm_path = self.copy_charm() |
| 204 sym_path = os.path.join(charm_path, 'foobar') |
| 205 os.symlink('metadata.yaml', sym_path) |
| 206 charm_dir = CharmDirectory(charm_path) |
| 207 normal_path = charm_dir.as_bundle().path |
| 208 zf_src = zipfile.ZipFile(normal_path, "r") |
| 209 foreign_path = os.path.join(self.makeDir(), "store.charm") |
| 210 zf_dst = zipfile.ZipFile(foreign_path, "w") |
| 211 for info in zf_src.infolist(): |
| 212 if info.filename == "foobar": |
| 213 # This is what the charm store does: |
| 214 info.external_attr = (stat.S_IFLNK | 0777) << 16 |
| 215 zf_dst.writestr(info, zf_src.read(info.filename)) |
| 216 zf_src.close() |
| 217 zf_dst.close() |
| 218 |
| 219 bundle = CharmBundle(foreign_path) |
| 220 extract_dir = self.makeDir() |
| 221 bundle.extract_to(extract_dir) |
| 222 self.assertIn("foobar", os.listdir(extract_dir)) |
| 223 self.assertTrue(os.path.islink(os.path.join(extract_dir, "foobar"))) |
| 224 self.assertEqual(os.readlink(os.path.join(extract_dir, 'foobar')), |
| 225 'metadata.yaml') |
| 226 |
198 def test_as_directory(self): | 227 def test_as_directory(self): |
199 filename = self.makeFile() | 228 filename = self.makeFile() |
200 charm = get_charm_from_path(self.filename) | 229 charm = get_charm_from_path(self.filename) |
201 f2 = charm.as_directory() | 230 f2 = charm.as_directory() |
202 | 231 |
203 # f2 should be a charm directory | 232 # f2 should be a charm directory |
204 self.assertInstance(f2, CharmDirectory) | 233 self.assertInstance(f2, CharmDirectory) |
205 self.assertInstance(f2.get_sha256(), basestring) | 234 self.assertInstance(f2.get_sha256(), basestring) |
206 # verify that it was extracted to a new temp dirname | 235 # verify that it was extracted to a new temp dirname |
207 self.assertNotEqual(f2.path, filename) | 236 self.assertNotEqual(f2.path, filename) |
208 | 237 |
209 fn = os.path.split(f2.path)[1] | 238 fn = os.path.split(f2.path)[1] |
210 # verify that it used the expected prefix | 239 # verify that it used the expected prefix |
211 self.assertStartsWith(fn, "tmp") | 240 self.assertStartsWith(fn, "tmp") |
LEFT | RIGHT |