From 96413decf9f4ed6cbfa814547de841cdc6b71e2d Mon Sep 17 00:00:00 2001 From: Binwei Fang Date: Thu, 8 Aug 2024 04:16:46 +0800 Subject: [PATCH] fix: add root folder alert --- main.go | 4 ++++ operation/upload.go | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 1c08835..f1ff66b 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,10 @@ import ( func main() { defer utils.TimeCost()() + if config.Folder == "/" { + fmt.Println("You should not upload the root directory, use ./ instead. 通常来说, 你不应该上传根目录, 也许你是要配置 ./") + os.Exit(1) + } if !config.SkipSetting { operation.SetStaticWebsiteConfig() diff --git a/operation/upload.go b/operation/upload.go index 40fe312..04cf716 100644 --- a/operation/upload.go +++ b/operation/upload.go @@ -2,6 +2,7 @@ package operation import ( "fmt" + "os" "path" "strings" "sync" @@ -20,7 +21,12 @@ type UploadedObject struct { // UploadObjects upload files to OSS func UploadObjects(root string, bucket *oss.Bucket, records <-chan utils.FileInfoType, i *IncrementalConfig) ([]UploadedObject, []error) { - root = path.Clean(root) + "/" + if root == "/" { + fmt.Println("You should not upload the root directory, use ./ instead. 通常来说, 你不应该上传根目录, 也许你是要配置 ./") + os.Exit(1) + } else { + root = path.Clean(root) + "/" + } var sw sync.WaitGroup var errorMutex sync.Mutex