Print this page
*** NO COMMENTS ***
| Split |
Close |
| Expand all |
| Collapse all |
--- old/src/gui/modules/filelist.py
+++ new/src/gui/modules/filelist.py
1 1 #!/usr/bin/python2.4
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 # Use is subject to license terms.
24 24 #
25 25
26 26 import os
27 27 import pkg.portable as portable
28 28 from pkg.misc import hash_file_name
29 29 import pkg.client.filelist as filelist
30 30
31 31 class FileList(filelist.FileList):
32 32
33 33 def __init__(self, progtrack, image, fmri, gui_thread = None, maxbytes = None):
34 34 self.progtrack = progtrack
35 35 self.gui_thread = gui_thread
36 36 filelist.FileList.__init__(self, image, fmri, progtrack, \
37 37 maxbytes = maxbytes)
38 38
39 39
40 40 def _extract_file(self, tarinfo, tar_stream, download_dir):
41 41 """Given a tarinfo object, extract that onto the filesystem
42 42 so it can be installed."""
43 43
44 44 if self.gui_thread.is_cancelled():
45 45 self.image.cleanup_downloads()
46 46 raise CancelException
47 47
48 48 completed_dir = self.image.cached_download_dir()
49 49
50 50 hashval = tarinfo.name
51 51
52 52 # Set the perms of the temporary file. The file must
53 53 # be writable so that the mod time can be changed on Windows
54 54 tarinfo.mode = 0600
55 55 tarinfo.uname = "root"
56 56 tarinfo.gname = "root"
57 57
58 58 # Now that the file has been successfully extracted, move
59 59 # it to the cached content directory.
60 60 final_path = os.path.normpath(os.path.join(completed_dir,
61 61 hash_file_name(hashval)))
62 62
63 63 # XXX catch IOError if tar stream closes inadvertently?
64 64 tar_stream.extract_to(tarinfo, download_dir, hashval)
65 65 # XXX Single file progress consumed by pkg.gui.installupdate
66 66 file_path = self.fhash[hashval][0].attrs.get("path")
67 67 self.progtrack.download_file_path(file_path)
|
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
68 68
69 69 if not os.path.exists(os.path.dirname(final_path)):
70 70 os.makedirs(os.path.dirname(final_path))
71 71
72 72 portable.rename(os.path.join(download_dir, hashval), final_path)
73 73
74 74 # assign opener to actions in the list
75 75 try:
76 76 lis = self.fhash[hashval]
77 77 except KeyError:
78 - # If the key isn't in the dictionary, the server
79 - # sent us a file we didn't ask for. In this
80 - # case, we can't create an opener for it, so just
81 - # leave it in the cache.
78 + # If the key isn't in the dictionary, the server sent us
79 + # a file we didn't ask for. In this case, we can't
80 + # create an opener for it, nor should we leave it in the
81 + # cache.
82 + os.remove(final_path)
82 83 return
83 84
85 + self._verify_content(lis[0], final_path)
86 +
84 87 for action in lis:
85 88 action.data = self._make_opener(final_path)
86 89
87 90 # Remove successfully extracted items from the hash
88 91 # and adjust bean counters
89 92 self._del_hash(hashval)
90 93
91 94 @staticmethod
92 95 def _make_opener(filepath):
93 96 def opener():
94 97 if self.gui_thread.is_cancelled():
95 98 self.image.cleanup_downloads()
96 99 raise CancelException
97 100 file_op = open(filepath, "rb")
98 101 os.unlink(filepath)
99 102 return file_op
100 103 return opener
101 104
102 105 class CancelException(Exception):
103 106 def __init__(self, args=None):
104 107 Exception.__init__(self)
105 108 self.args = args
106 109
107 110 class FileListException(Exception):
108 111 def __init__(self, args = None):
109 112 Exception.__init__(self)
110 113 self.args = args
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX