Skip to content

Commit 729be09

Browse files
committed
Merge branch 'fix-panic-short-id' into 'main'
Fix panic with short IDs Closes #33 See merge request bootc-org/podman-bootc-cli!69
2 parents bddf552 + 34b9978 commit 729be09

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

pkg/vm/vm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ import (
2525
var ErrVMInUse = errors.New("VM already in use")
2626

2727
// GetVMCachePath returns the path to the VM cache directory
28-
func GetVMCachePath(imageId string, user user.User) (path string, err error) {
28+
func GetVMCachePath(imageId string, user user.User) (longID string, path string, err error) {
2929
files, err := os.ReadDir(user.CacheDir())
3030
if err != nil {
31-
return "", err
31+
return "", "", err
3232
}
3333

3434
fullImageId := ""
3535
for _, f := range files {
36-
if f.IsDir() && strings.HasPrefix(f.Name(), imageId) {
36+
if f.IsDir() && len(f.Name()) == 64 && strings.HasPrefix(f.Name(), imageId) {
3737
fullImageId = f.Name()
3838
}
3939
}
4040

4141
if fullImageId == "" {
42-
return "", fmt.Errorf("local installation '%s' does not exists", imageId)
42+
return "", "", fmt.Errorf("local installation '%s' does not exists", imageId)
4343
}
4444

45-
return filepath.Join(user.CacheDir(), fullImageId), nil
45+
return fullImageId, filepath.Join(user.CacheDir(), fullImageId), nil
4646
}
4747

4848
type NewVMParameters struct {

pkg/vm/vm_darwin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewVM(params NewVMParameters) (vm *BootcVMMac, err error) {
2525
return nil, fmt.Errorf("image ID is required")
2626
}
2727

28-
cacheDir, err := GetVMCachePath(params.ImageID, params.User)
28+
longId, cacheDir, err := GetVMCachePath(params.ImageID, params.User)
2929
if err != nil {
3030
return nil, fmt.Errorf("unable to get VM cache path: %w", err)
3131
}
@@ -36,9 +36,9 @@ func NewVM(params NewVMParameters) (vm *BootcVMMac, err error) {
3636
}
3737

3838
vm = &BootcVMMac{
39-
socketFile: filepath.Join(params.User.CacheDir(), params.ImageID[:12]+"-console.sock"),
39+
socketFile: filepath.Join(params.User.CacheDir(), longId[:12]+"-console.sock"),
4040
BootcVMCommon: BootcVMCommon{
41-
imageID: params.ImageID,
41+
imageID: longId,
4242
cacheDir: cacheDir,
4343
diskImagePath: filepath.Join(cacheDir, config.DiskImage),
4444
pidFile: filepath.Join(cacheDir, config.RunPidFile),

pkg/vm/vm_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewVM(params NewVMParameters) (vm *BootcVMLinux, err error) {
3939
return nil, fmt.Errorf("libvirt URI is required")
4040
}
4141

42-
cacheDir, err := GetVMCachePath(params.ImageID, params.User)
42+
longId, cacheDir, err := GetVMCachePath(params.ImageID, params.User)
4343
if err != nil {
4444
return nil, fmt.Errorf("unable to get VM cache path: %w", err)
4545
}
@@ -52,8 +52,8 @@ func NewVM(params NewVMParameters) (vm *BootcVMLinux, err error) {
5252
vm = &BootcVMLinux{
5353
libvirtUri: params.LibvirtUri,
5454
BootcVMCommon: BootcVMCommon{
55-
vmName: vmName(params.ImageID),
56-
imageID: params.ImageID,
55+
vmName: vmName(longId),
56+
imageID: longId,
5757
cacheDir: cacheDir,
5858
diskImagePath: filepath.Join(cacheDir, config.DiskImage),
5959
user: params.User,

0 commit comments

Comments
 (0)