Skip to content

Commit

Permalink
Open returns snapshot metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Nov 16, 2013
1 parent 48fe3d7 commit 9bd1fb3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions file_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,20 @@ func (f *FileSnapshotStore) readMeta(name string) (*fileSnapshotMeta, error) {
return meta, nil
}

func (f *FileSnapshotStore) Open(id string) (io.ReadCloser, error) {
func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) {
// Get the metadata
meta, err := f.readMeta(id)
if err != nil {
log.Printf("[ERR] Failed to get meta data to open snapshot: %v", err)
return nil, err
return nil, nil, err
}

// Open the state file
statePath := filepath.Join(f.path, id, stateFilePath)
fh, err := os.Open(statePath)
if err != nil {
log.Printf("[ERR] Failed to open state file: %v", err)
return nil, err
return nil, nil, err
}

// Create a CRC64 hash
Expand All @@ -261,7 +261,7 @@ func (f *FileSnapshotStore) Open(id string) (io.ReadCloser, error) {
if err != nil {
log.Printf("[ERR] Failed to read state file: %v", err)
fh.Close()
return nil, err
return nil, nil, err
}

// Verify the hash
Expand All @@ -270,14 +270,14 @@ func (f *FileSnapshotStore) Open(id string) (io.ReadCloser, error) {
log.Printf("[ERR] CRC checksum failed (stored: %v computed: %v)",
meta.CRC, computed)
fh.Close()
return nil, fmt.Errorf("CRC mismatch")
return nil, nil, fmt.Errorf("CRC mismatch")
}

// Seek to the start
if _, err := fh.Seek(0, 0); err != nil {
log.Printf("[ERR] State file seek failed: %v", err)
fh.Close()
return nil, err
return nil, nil, err
}

// Return a buffered file
Expand All @@ -286,7 +286,7 @@ func (f *FileSnapshotStore) Open(id string) (io.ReadCloser, error) {
fh: fh,
}

return buffered, nil
return &meta.SnapshotMeta, buffered, nil
}

// Used to reap any snapshots beyond the retain count
Expand Down
2 changes: 1 addition & 1 deletion file_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) {
}

// Read the snapshot
r, err := snap.Open(latest.ID)
_, r, err := snap.Open(latest.ID)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SnapshotStore interface {

// Open takes a snapshot ID and provides a ReadCloser. Once close is
// called it is assumed the snapshot is no longer needed.
Open(id string) (io.ReadCloser, error)
Open(id string) (*SnapshotMeta, io.ReadCloser, error)
}

// SnapshotSink is returned by StartSnapshot. The FSM will Write state
Expand Down

0 comments on commit 9bd1fb3

Please sign in to comment.