129
131
for name in self._pack_names():
130
132
if name.startswith("pack-") and name.endswith(".pack"):
131
pd = PackData(name, self.pack_transport.get(name))
133
size = self.pack_transport.stat(name).st_size
134
pd = PackData(name, self.pack_transport.get(name), size=size)
132
135
idxname = name.replace(".pack", ".idx")
133
136
idx = load_pack_index_file(idxname, self.pack_transport.get(idxname))
134
137
ret.append(Pack.from_objects(pd, idx))
166
169
return # Already there, no need to write again
167
170
self.transport.put_bytes(path, obj.as_legacy_object())
172
def move_in_pack(self, path):
173
"""Move a specific file containing a pack into the pack directory.
175
:note: The file should be on the same file system as the
178
:param path: Path to the pack file.
182
entries = p.sorted_entries()
183
basename = os.path.join(self.pack_transport.local_abspath('.'),
184
"pack-%s" % iter_sha1(entry[0] for entry in entries))
185
write_pack_index_v2(basename+".idx", entries, p.get_stored_checksum())
187
os.rename(path, basename + ".pack")
188
final_pack = Pack(basename)
189
self._add_known_pack(final_pack)
169
192
def add_pack(self):
170
193
"""Add a new pack to this object store.
172
195
:return: Fileobject to write to and a commit function to
173
196
call when the pack is finished.
175
raise NotImplementedError(self.add_pack)
199
fd, path = tempfile.mkstemp(dir=self.pack_transport.local_abspath('.'), suffix=".pack")
200
f = os.fdopen(fd, 'wb')
203
if os.path.getsize(path) > 0:
204
return self.move_in_pack(path)
178
210
def init(cls, transport):