Skip to content

Commit

Permalink
don't panic if iso is not in db, create new entry
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankT1983 committed Jun 26, 2023
1 parent f14995c commit 13533c3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var (
ErrBucketNotFound = errors.New("bucket not found")
ErrStoragePathNotSet = errors.New("storage path not set")
ErrClientInit = errors.New("client not initialised")

DataBaseName = "uii.db"
)

// IUiiClient is an interface for abstracting the interactions with the UII service - used for testing
Expand Down Expand Up @@ -52,7 +54,7 @@ func (s *clientWithStorage) CreateIso(iso Iso) (StoredIso, error) {
return StoredIso{}, ErrStoragePathNotSet
}

db, err := setupDB(path.Join(s.StorageFolder, "my.db"))
db, err := setupDB(path.Join(s.StorageFolder, DataBaseName))
if err != nil {
log.Fatal(err)
return StoredIso{}, err
Expand Down Expand Up @@ -84,7 +86,7 @@ func (s *clientWithStorage) CreateIso(iso Iso) (StoredIso, error) {

// ReadIso reads a ISO resource
func (s *clientWithStorage) ReadIso(isoID string) (StoredIso, error) {
db, err := setupDB(path.Join(s.StorageFolder, "my.db"))
db, err := setupDB(path.Join(s.StorageFolder, DataBaseName))
if err != nil {
log.Fatal(err)
return StoredIso{}, err
Expand Down Expand Up @@ -116,7 +118,7 @@ func (s *clientWithStorage) ReadDistributions() ([]client.OS, error) {

// DeleteIso reads a ISO resource
func (s *clientWithStorage) DeleteIso(isoID string) error {
db, err := setupDB(path.Join(s.StorageFolder, "my.db"))
db, err := setupDB(path.Join(s.StorageFolder, DataBaseName))
if err != nil {
log.Panic(err)
return err
Expand All @@ -134,20 +136,16 @@ func (s *clientWithStorage) DeleteIso(isoID string) error {

// UpdateIso updates a ISO resource
func (s *clientWithStorage) UpdateIso(id string, iso Iso) error {
db, err := setupDB(path.Join(s.StorageFolder, "my.db"))
db, err := setupDB(path.Join(s.StorageFolder, DataBaseName))
if err != nil {
log.Panic(err)
return err
}
defer db.Close()

oldIso, err := readIso(db, id)
if err != nil {
log.Panic(err)
return err
}

if requiresNewIsoFile(iso, oldIso) {
if err != nil || requiresNewIsoFile(iso, oldIso) {
// refresh iso and re-read, as path potentially updated
err = s.refreshIso(id, db)
if err != nil {
Expand Down

0 comments on commit 13533c3

Please sign in to comment.