@@ -116,7 +116,12 @@ func (context *AptlyContext) config() *utils.ConfigStructure {
116116 if err != nil {
117117 fmt .Fprintf (os .Stderr , "Config file not found, creating default config at %s\n \n " , homeLocation )
118118
119- _ = utils .SaveConfigRaw (homeLocation , aptly .AptlyConf )
119+ defaultConfig := aptly .AptlyConf
120+ if len (defaultConfig ) == 0 {
121+ defaultConfig = []byte ("root_dir: \" \" " )
122+ }
123+
124+ _ = utils .SaveConfigRaw (homeLocation , defaultConfig )
120125 err = utils .LoadConfig (homeLocation , & utils .Config )
121126 if err != nil {
122127 Fatal (fmt .Errorf ("error loading config file %s: %s" , homeLocation , err ))
@@ -407,8 +412,8 @@ func (context *AptlyContext) PackagePool() aptly.PackagePool {
407412 return context .packagePool
408413}
409414
410- // GetPublishedStorage returns instance of PublishedStorage
411- func (context * AptlyContext ) GetPublishedStorage (name string ) aptly.PublishedStorage {
415+ // GetPublishedStorage returns instance of PublishedStorage, or an error if the storage is not configured
416+ func (context * AptlyContext ) GetPublishedStorage (name string ) ( aptly.PublishedStorage , error ) {
412417 context .Lock ()
413418 defer context .Unlock ()
414419
@@ -419,14 +424,14 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
419424 } else if strings .HasPrefix (name , "filesystem:" ) {
420425 params , ok := context .config ().FileSystemPublishRoots [name [11 :]]
421426 if ! ok {
422- Fatal ( fmt .Errorf ("published local storage %v not configured" , name [11 :]) )
427+ return nil , fmt .Errorf ("published local storage %v not configured" , name [11 :])
423428 }
424429
425430 publishedStorage = files .NewPublishedStorage (params .RootDir , params .LinkMethod , params .VerifyMethod )
426431 } else if strings .HasPrefix (name , "s3:" ) {
427432 params , ok := context .config ().S3PublishRoots [name [3 :]]
428433 if ! ok {
429- Fatal ( fmt .Errorf ("published S3 storage %v not configured" , name [3 :]) )
434+ return nil , fmt .Errorf ("published S3 storage %v not configured" , name [3 :])
430435 }
431436
432437 var err error
@@ -436,39 +441,39 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
436441 params .EncryptionMethod , params .PlusWorkaround , params .DisableMultiDel ,
437442 params .ForceSigV2 , params .ForceVirtualHostedStyle , params .Debug )
438443 if err != nil {
439- Fatal ( err )
444+ return nil , err
440445 }
441446 } else if strings .HasPrefix (name , "swift:" ) {
442447 params , ok := context .config ().SwiftPublishRoots [name [6 :]]
443448 if ! ok {
444- Fatal ( fmt .Errorf ("published Swift storage %v not configured" , name [6 :]) )
449+ return nil , fmt .Errorf ("published Swift storage %v not configured" , name [6 :])
445450 }
446451
447452 var err error
448453 publishedStorage , err = swift .NewPublishedStorage (params .UserName , params .Password ,
449454 params .AuthURL , params .Tenant , params .TenantID , params .Domain , params .DomainID , params .TenantDomain , params .TenantDomainID , params .Container , params .Prefix )
450455 if err != nil {
451- Fatal ( err )
456+ return nil , err
452457 }
453458 } else if strings .HasPrefix (name , "azure:" ) {
454459 params , ok := context .config ().AzurePublishRoots [name [6 :]]
455460 if ! ok {
456- Fatal ( fmt .Errorf ("published Azure storage %v not configured" , name [6 :]) )
461+ return nil , fmt .Errorf ("published Azure storage %v not configured" , name [6 :])
457462 }
458463
459464 var err error
460465 publishedStorage , err = azure .NewPublishedStorage (
461466 params .AccountName , params .AccountKey , params .Container , params .Prefix , params .Endpoint )
462467 if err != nil {
463- Fatal ( err )
468+ return nil , err
464469 }
465470 } else {
466- Fatal ( fmt .Errorf ("unknown published storage format: %v" , name ) )
471+ return nil , fmt .Errorf ("unknown published storage format: %v" , name )
467472 }
468473 context .publishedStorages [name ] = publishedStorage
469474 }
470475
471- return publishedStorage
476+ return publishedStorage , nil
472477}
473478
474479// UploadPath builds path to upload storage
0 commit comments