Skip to content

Commit 4962b64

Browse files
committed
reader: add method to get Primary Volume label
1 parent 30ab35f commit 4962b64

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

image_reader.go

+10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ func (i *Image) RootDir() (*File, error) {
6262
return nil, os.ErrNotExist
6363
}
6464

65+
// RootDir returns the label of the first Primary Volume
66+
func (i *Image) Label() (string, error) {
67+
for _, vd := range i.volumeDescriptors {
68+
if vd.Type() == volumeTypePrimary {
69+
return string(vd.Primary.VolumeIdentifier), nil
70+
}
71+
}
72+
return "", os.ErrNotExist
73+
}
74+
6575
// File is a os.FileInfo-compatible wrapper around an ISO9660 directory entry
6676
type File struct {
6777
ra io.ReaderAt

image_reader_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func TestImageReader(t *testing.T) {
3030
assert.Equal(t, volumeTypeTerminator, image.volumeDescriptors[1].Header.Type)
3131
}
3232

33+
label, err := image.Label()
34+
assert.NoError(t, err)
35+
assert.Equal(t, "my-vol-id", label)
36+
3337
rootDir, err := image.RootDir()
3438
assert.NoError(t, err)
3539
assert.True(t, rootDir.IsDir())

0 commit comments

Comments
 (0)