aboutsummaryrefslogtreecommitdiff
path: root/object/store/packed/store_open_pack.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-25 14:30:31 +0000
committerGravatar Runxi Yu2026-03-25 14:30:31 +0000
commitbfa0a3f5f18b752a6ebd3d5b37411c6871f7bb17 (patch)
tree8ee2479273e2b34d284c30703c2be48efe197556 /object/store/packed/store_open_pack.go
parent*: Resort import order (diff)
signatureNo signature
*: objectstore -> object/store
Diffstat (limited to 'object/store/packed/store_open_pack.go')
-rw-r--r--object/store/packed/store_open_pack.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/object/store/packed/store_open_pack.go b/object/store/packed/store_open_pack.go
new file mode 100644
index 00000000..c621e08c
--- /dev/null
+++ b/object/store/packed/store_open_pack.go
@@ -0,0 +1,57 @@
+package packed
+
+// openPack returns one opened and validated pack handle.
+func (store *Store) openPack(name string) (*packFile, error) {
+ store.stateMu.RLock()
+
+ pack, ok := store.packs[name]
+ if ok {
+ store.stateMu.RUnlock()
+
+ return pack, nil
+ }
+
+ store.stateMu.RUnlock()
+
+ file, err := store.root.Open(name)
+ if err != nil {
+ return nil, err
+ }
+
+ info, err := file.Stat()
+ if err != nil {
+ _ = file.Close()
+
+ return nil, err
+ }
+
+ pack, err = openPackFile(name, file, info.Size())
+ if err != nil {
+ _ = file.Close()
+
+ return nil, err
+ }
+
+ err = store.verifyPackMatchesIndexes(pack)
+ if err != nil {
+ _ = pack.close()
+
+ return nil, err
+ }
+
+ store.stateMu.Lock()
+
+ existing, ok := store.packs[name]
+ if ok {
+ store.stateMu.Unlock()
+
+ _ = pack.close()
+
+ return existing, nil
+ }
+
+ store.packs[name] = pack
+ store.stateMu.Unlock()
+
+ return pack, nil
+}