Skip to content

Commit

Permalink
Tweak cache logic so an empty string is not considered a cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bbockelm committed Feb 29, 2024
1 parent e748c28 commit c6c1861
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ func getCachesFromNamespace(namespace namespaces.Namespace, useDirector bool, pr

// The global cache override is set
if len(preferredCaches) > 0 {
if preferredCaches[0].String() == "" {
err = errors.New("Preferred cache was specified as an empty string")
return
}
log.Debugf("Using the cache (%s) from the config override\n", preferredCaches[0])
cache := namespaces.Cache{
Endpoint: preferredCaches[0].String(),
Expand Down
15 changes: 9 additions & 6 deletions cmd/object_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,15 @@ func copyMain(cmd *cobra.Command, args []string) {
} else if cache, _ := cmd.Flags().GetString("cache"); cache != "" {
preferredCache = cache
}
caches := make([]*url.URL, 1)
if preferredCacheURL, err := url.Parse(preferredCache); err != nil {
log.Errorf("Unable to parse preferred cache (%s) as URL: %s", preferredCache, err.Error())
} else {
caches[0] = preferredCacheURL
log.Debugln("Preferred cache for transfer:", preferredCacheURL)
caches := make([]*url.URL, 0, 1)
if preferredCache != "" {
if preferredCacheURL, err := url.Parse(preferredCache); err != nil {
log.Errorf("Unable to parse preferred cache (%s) as URL: %s", preferredCache, err.Error())
os.Exit(1)
} else {
caches = append(caches, preferredCacheURL)
log.Debugln("Preferred cache for transfer:", preferredCacheURL)
}
}

if len(source) > 1 {
Expand Down
15 changes: 9 additions & 6 deletions cmd/object_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ func getMain(cmd *cobra.Command, args []string) {
} else if cache, _ := cmd.Flags().GetString("cache"); cache != "" {
preferredCache = cache
}
caches := make([]*url.URL, 1)
if preferredCacheURL, err := url.Parse(preferredCache); err != nil {
log.Errorf("Unable to parse preferred cache (%s) as URL: %s", preferredCache, err.Error())
} else {
caches[0] = preferredCacheURL
log.Debugln("Preferred cache for transfer:", preferredCacheURL)
caches := make([]*url.URL, 0, 1)
if preferredCache != "" {
if preferredCacheURL, err := url.Parse(preferredCache); err != nil {
log.Errorf("Unable to parse preferred cache (%s) as URL: %s", preferredCache, err.Error())
os.Exit(1)
} else {
caches = append(caches, preferredCacheURL)
log.Debugln("Preferred cache for transfer:", preferredCacheURL)
}
}

if len(source) > 1 {
Expand Down

0 comments on commit c6c1861

Please sign in to comment.