66 (pkgplan.image.get_root(), path))) |
66 (pkgplan.image.get_root(), path))) |
67 |
67 |
68 if not os.path.exists(os.path.dirname(final_path)): |
68 if not os.path.exists(os.path.dirname(final_path)): |
69 self.makedirs(os.path.dirname(final_path), mode=0755) |
69 self.makedirs(os.path.dirname(final_path), mode=0755) |
70 |
70 |
71 # If we're upgrading, extract the attributes from the old file. |
71 |
72 if orig: |
72 # XXX If we're upgrading, do we need to preserve file perms from |
73 omode = int(orig.attrs["mode"], 8) |
73 # exiting file? |
74 oowner = pkgplan.image.get_user_by_name( |
|
75 orig.attrs["owner"]) |
|
76 ogroup = pkgplan.image.get_group_by_name( |
|
77 orig.attrs["group"]) |
|
78 ohash = orig.hash |
|
79 |
74 |
80 # If the action has been marked with a preserve attribute, and |
75 # If the action has been marked with a preserve attribute, and |
81 # the file exists and has a contents hash different from what |
76 # the file exists and has a contents hash different from what |
82 # the system expected it to be, then we preserve the original |
77 # the system expected it to be, then we preserve the original |
83 # file in some way, depending on the value of preserve. |
78 # file in some way, depending on the value of preserve. |
90 chash = sha.sha(cfile.read()).hexdigest() |
85 chash = sha.sha(cfile.read()).hexdigest() |
91 |
86 |
92 # XXX We should save the originally installed file. It |
87 # XXX We should save the originally installed file. It |
93 # can be used as an ancestor for a three-way merge, for |
88 # can be used as an ancestor for a three-way merge, for |
94 # example. Where should it be stored? |
89 # example. Where should it be stored? |
95 if not orig or chash != ohash: |
90 if not orig or chash != orig.hash: |
96 pres_type = self.attrs["preserve"] |
91 pres_type = self.attrs["preserve"] |
97 if pres_type == "renameold": |
92 if pres_type == "renameold": |
98 old_path = final_path + ".old" |
93 old_path = final_path + ".old" |
99 elif pres_type == "renamenew": |
94 elif pres_type == "renamenew": |
100 final_path = final_path + ".new" |
95 final_path = final_path + ".new" |
131 portable.rename(final_path, old_path) |
126 portable.rename(final_path, old_path) |
132 |
127 |
133 # This is safe even if temp == final_path. |
128 # This is safe even if temp == final_path. |
134 portable.rename(temp, final_path) |
129 portable.rename(temp, final_path) |
135 |
130 |
136 # XXX .pyc files are causing problems because they're not enough |
131 # Handle timestamp if specified |
137 # newer than the .py files.... if we just installed a .pyc |
132 if "timestamp" in self.attrs: |
138 # file, move its modification time into the future to prevent |
133 t = misc.timestamp_to_time(self.attrs["timestamp"]) |
139 # python commands running as root from updating these files |
|
140 # because they look out of date... the right fix is to fix |
|
141 # Solaris python to look at the entire timestamp.... pending. |
|
142 # in the mean time, this "accomodation" has to be made to |
|
143 # prevent pkg verify errors. |
|
144 if final_path.endswith(".pyc"): |
|
145 t = os.stat(final_path)[ST_MTIME] + 5 # magic |
|
146 os.utime(final_path, (t, t)) |
134 os.utime(final_path, (t, t)) |
147 |
135 |
148 def verify(self, img, **args): |
136 def verify(self, img, **args): |
149 """ verify that file is present and if preserve attribute |
137 """ verify that file is present and if preserve attribute |
150 not present, that hashes match""" |
138 not present, that hashes match""" |
183 img.get_name_by_gid(group, True))) |
171 img.get_name_by_gid(group, True))) |
184 if S_IMODE(stat[ST_MODE]) != mode: |
172 if S_IMODE(stat[ST_MODE]) != mode: |
185 errors.append("Mode: 0%.3o should be 0%.3o" % \ |
173 errors.append("Mode: 0%.3o should be 0%.3o" % \ |
186 (S_IMODE(stat[ST_MODE]), mode)) |
174 (S_IMODE(stat[ST_MODE]), mode)) |
187 |
175 |
|
176 if "timestamp" in self.attrs and stat[ST_MTIME] != \ |
|
177 misc.timestamp_to_time(self.attrs["timestamp"]): |
|
178 errors.append("Timestamp: %s should be %s" % |
|
179 (misc.time_to_timestamp(stat[ST_MTIME]), |
|
180 self.attrs["timestamp"])) |
|
181 |
188 # avoid checking pkg.size if elfhash present; |
182 # avoid checking pkg.size if elfhash present; |
189 # different size files may have the same elfhash |
183 # different size files may have the same elfhash |
190 if "preserve" not in self.attrs and \ |
184 if "preserve" not in self.attrs and \ |
191 "pkg.size" in self.attrs and \ |
185 "pkg.size" in self.attrs and \ |
192 "elfhash" not in self.attrs and \ |
186 "elfhash" not in self.attrs and \ |