gcs-client: Return error when download dir missing If DownloadDir is called for a GCS path which has no descendants, this should be an error since it implies that the corresponding virtual GCS directory does not actually exist. BUG=None TEST=presubmit Change-Id: I84773248773f93cf7f51166774b5cae8a1db078d Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/163225 Cloud-Build: 228075978874@cloudbuild.gserviceaccount.com <228075978874@cloudbuild.gserviceaccount.com> Reviewed-by: Angel Adetula <angeladetula@google.com> Tested-by: Kevin Berry <kpberry@google.com>
diff --git a/src/pkg/gcs/gcs_client.go b/src/pkg/gcs/gcs_client.go index 57709f3..7c6b9c6 100644 --- a/src/pkg/gcs/gcs_client.go +++ b/src/pkg/gcs/gcs_client.go
@@ -323,6 +323,13 @@ return nil, err } + if len(descendants) == 0 { + return nil, fmt.Errorf( + "no descendants found for %s; either the bucket does not exist, or you do not have the required permissions to access it", + bucket.URI(bucketDir), + ) + } + var downloads []ObjectDownload for _, objectName := range descendants { // In a GCS bucket, the paths some/path and /some/path are different.