From 866834c79a734ecb0e494b5eaadd187e826c315c Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Fri, 24 Jul 2020 23:04:14 +0000 Subject: [PATCH 1/2] Check if skippedFiles directory exists --- kotsadm/pkg/handlers/download.go | 7 ++++++- kotsadm/pkg/version/archive.go | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kotsadm/pkg/handlers/download.go b/kotsadm/pkg/handlers/download.go index eebbc3b018..e580568c65 100644 --- a/kotsadm/pkg/handlers/download.go +++ b/kotsadm/pkg/handlers/download.go @@ -86,8 +86,13 @@ func DownloadApp(w http.ResponseWriter, r *http.Request) { filepath.Join(archivePath, "upstream"), filepath.Join(archivePath, "base"), filepath.Join(archivePath, "overlays"), - filepath.Join(archivePath, "skippedFiles"), } + + skippedFilesPath := filepath.Join(archivePath, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) + } + tmpDir, err := ioutil.TempDir("", "kotsadm") if err != nil { logger.Error(err) diff --git a/kotsadm/pkg/version/archive.go b/kotsadm/pkg/version/archive.go index 5e79ee55fe..0a24a93f0a 100644 --- a/kotsadm/pkg/version/archive.go +++ b/kotsadm/pkg/version/archive.go @@ -32,7 +32,11 @@ func CreateAppVersionArchive(appID string, sequence int64, archivePath string) e filepath.Join(archivePath, "upstream"), filepath.Join(archivePath, "base"), filepath.Join(archivePath, "overlays"), - filepath.Join(archivePath, "skippedFiles"), + } + + skippedFilesPath := filepath.Join(archivePath, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) } tmpDir, err := ioutil.TempDir("", "kotsadm") From f85a6fdf8d5e3694114395df017ef713766add88 Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Fri, 24 Jul 2020 23:06:23 +0000 Subject: [PATCH 2/2] Check if skippedFiles directory exists everywhere, why not --- ffi/main.go | 6 +++++- ffi/online.go | 6 +++++- ffi/updatedownload.go | 12 ++++++++++-- integration/replicated/generate.go | 5 ++++- pkg/pull/archive.go | 6 +++++- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/ffi/main.go b/ffi/main.go index 8dbbb4fbe5..63453b25cb 100644 --- a/ffi/main.go +++ b/ffi/main.go @@ -98,7 +98,11 @@ func UpdateCheck(socket, fromArchivePath, namespace string) { filepath.Join(tmpRoot, "upstream"), filepath.Join(tmpRoot, "base"), filepath.Join(tmpRoot, "overlays"), - filepath.Join(tmpRoot, "skippedFiles"), + } + + skippedFilesPath := filepath.Join(tmpRoot, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) } err = os.Remove(fromArchivePath) diff --git a/ffi/online.go b/ffi/online.go index 27d85e3346..381901f5f9 100644 --- a/ffi/online.go +++ b/ffi/online.go @@ -161,7 +161,11 @@ func RewriteVersion(socket, fromArchivePath, outputFile, downstreamsStr, k8sName filepath.Join(tmpRoot, "upstream"), filepath.Join(tmpRoot, "base"), filepath.Join(tmpRoot, "overlays"), - filepath.Join(tmpRoot, "skippedFiles"), + } + + skippedFilesPath := filepath.Join(tmpRoot, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) } if err := tarGz.Archive(paths, outputFile); err != nil { diff --git a/ffi/updatedownload.go b/ffi/updatedownload.go index e84b081a5d..c09a919d06 100644 --- a/ffi/updatedownload.go +++ b/ffi/updatedownload.go @@ -119,7 +119,11 @@ func UpdateDownload(socket, fromArchivePath, namespace, registryJson, cursor str filepath.Join(tmpRoot, "upstream"), filepath.Join(tmpRoot, "base"), filepath.Join(tmpRoot, "overlays"), - filepath.Join(tmpRoot, "skippedFiles"), + } + + skippedFilesPath := filepath.Join(tmpRoot, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) } err = os.Remove(fromArchivePath) @@ -294,7 +298,11 @@ func UpdateDownloadFromAirgap(socket, fromArchivePath, namespace, registryJson, filepath.Join(tmpRoot, "upstream"), filepath.Join(tmpRoot, "base"), filepath.Join(tmpRoot, "overlays"), - filepath.Join(tmpRoot, "skippedFiles"), + } + + skippedFilesPath := filepath.Join(tmpRoot, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) } err = os.Remove(fromArchivePath) diff --git a/integration/replicated/generate.go b/integration/replicated/generate.go index dab43d3f55..f4b77844f8 100644 --- a/integration/replicated/generate.go +++ b/integration/replicated/generate.go @@ -144,7 +144,10 @@ func generateExpectedFilesystem(namespace, rawArchivePath string) ([]byte, error path.Join(tmpRootDir, "upstream"), path.Join(tmpRootDir, "base"), path.Join(tmpRootDir, "overlays"), - path.Join(tmpRootDir, "skippedFiles"), + } + skippedFilesPath := path.Join(tmpRootDir, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) } if err := tarGz.Archive(paths, archiveFile); err != nil { return nil, errors.Wrap(err, "failed to create archive") diff --git a/pkg/pull/archive.go b/pkg/pull/archive.go index e4d454ba2d..b00e4a12b7 100644 --- a/pkg/pull/archive.go +++ b/pkg/pull/archive.go @@ -32,7 +32,11 @@ func writeArchiveAsConfigMap(pullOptions PullOptions, u *upstreamtypes.Upstream, path.Join(pullOptions.RootDir, u.Name, "upstream"), path.Join(pullOptions.RootDir, u.Name, "base"), path.Join(pullOptions.RootDir, u.Name, "overlays"), - path.Join(pullOptions.RootDir, u.Name, "skippedFiles"), + } + + skippedFilesPath := path.Join(pullOptions.RootDir, "skippedFiles") + if _, err := os.Stat(skippedFilesPath); err == nil { + paths = append(paths, skippedFilesPath) } tempDir, err := ioutil.TempDir("", "kots")