Skip to content

Commit

Permalink
reader: add method to get Primary Volume label
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomanski committed May 21, 2023
1 parent 7d7a089 commit e3b8a75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions image_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ func (i *Image) RootDir() (*File, error) {
return nil, os.ErrNotExist
}

// RootDir returns the label of the first Primary Volume
func (i *Image) Label() (string, error) {
for _, vd := range i.volumeDescriptors {
if vd.Type() == volumeTypePrimary {
return string(vd.Primary.VolumeIdentifier), nil
}
}
return "", os.ErrNotExist
}

// File is a os.FileInfo-compatible wrapper around an ISO9660 directory entry
type File struct {
ra io.ReaderAt
Expand Down
4 changes: 4 additions & 0 deletions image_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestImageReader(t *testing.T) {
assert.Equal(t, volumeTypeTerminator, image.volumeDescriptors[1].Header.Type)
}

label, err := image.Label()
assert.NoError(t, err)
assert.Equal(t, "my-vol-id", label)

rootDir, err := image.RootDir()
assert.NoError(t, err)
assert.True(t, rootDir.IsDir())
Expand Down

0 comments on commit e3b8a75

Please sign in to comment.