From 41ccd7651c31026a18f2b057a0f812810d23b52e Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Wed, 31 Mar 2021 15:30:25 -0700 Subject: [PATCH] Fixup for old file path --- server/app/files.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/server/app/files.go b/server/app/files.go index 6ad756158..2bc2d7b7e 100644 --- a/server/app/files.go +++ b/server/app/files.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "io" + "log" + "os" "path/filepath" "strings" @@ -32,5 +34,25 @@ func (a *App) GetFilePath(workspaceID, rootID, filename string) string { folderPath := a.config.FilesPath rootPath := filepath.Join(folderPath, workspaceID, rootID) - return filepath.Join(rootPath, filename) + filePath := filepath.Join(rootPath, filename) + + // FIXUP: Check the deprecated old location + if workspaceID == "0" && !fileExists(filePath) { + oldFilePath := filepath.Join(folderPath, filename) + if fileExists(oldFilePath) { + err := os.Rename(oldFilePath, filePath) + if err != nil { + log.Printf("ERROR moving old file from '%s' to '%s'", oldFilePath, filePath) + } else { + log.Printf("Moved old file from '%s' to '%s'", oldFilePath, filePath) + } + } + } + + return filePath +} + +func fileExists(path string) bool { + _, err := os.Stat(path) + return !os.IsNotExist(err) }