Skip to content

Commit

Permalink
hotfix upload path error
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxso committed Dec 10, 2023
1 parent 041e022 commit 973b7e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
34 changes: 2 additions & 32 deletions cloudsync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/karrick/godirwalk"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -101,8 +100,8 @@ func SyncFolder() error {
cloudMD5 := couldMd5FileMap[filename]
targetMD5, _ := redisCli.HGet(redisCli.Context(), UPLOAD_PATHS, cloudMD5).Result()
if sourceMD5 != targetMD5 {
logrus.Info("filename: ", filename, " md5: ", sourceMD5, " Upload File")
respMD5, err := upload.Upload(relativePath, path)
logrus.Info("filename: ", filepath.Join(targetFolder, relativePath, filename), " md5: ", sourceMD5, " Upload File")
respMD5, err := upload.Upload(filepath.Join(targetFolder, relativePath, filename), path)
if err != nil {
panic(err)
}
Expand All @@ -127,35 +126,6 @@ func SyncFolder() error {
redisCli.HSet(redisCli.Context(), DOWNLOAD_PATHS, fidMap[path], false)
}
}
// 上传或者下载这些文件
// 上传
for path := range redisCli.HGetAll(redisCli.Context(), UPLOAD_PATHS).Val() {
if redisCli.HGet(redisCli.Context(), UPLOAD_PATHS, path).Val() == "false" {
uploadCount++
logrus.Infof("Upload Source File Name [%s]", path)
if err != nil {
return err
}
upload.Upload(path, sourceFolder)
uploadCount++
redisCli.HSet(redisCli.Context(), UPLOAD_PATHS, path, true)
}
}
// 下载
for path := range redisCli.HGetAll(redisCli.Context(), DOWNLOAD_PATHS).Val() {
if redisCli.HGet(redisCli.Context(), DOWNLOAD_PATHS, path).Val() == "false" {
uploadCount++
logrus.Infof("Upload Source File Name [%s]", path)
fid, err := strconv.ParseUint(path, 10, 64)
if err != nil {
return err
}
download.Download(fid, sourceFolder)
downloadCount++
redisCli.HSet(redisCli.Context(), DOWNLOAD_PATHS, path, true)
}
}

logrus.Info("Waiting Count: ", waitingCount, " Upload Count: ", uploadCount, " Download Count: ", downloadCount, " Skip Count: ", skipCount, " CloudFile Count: ", len(couldMd5FileMap))
return nil
}
Expand Down
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"io"
_ "net/http/pprof"
"os"

Expand All @@ -18,20 +19,20 @@ const (
func main() {
defer handler.HandlerGlobalErrors()
defer db.CloseRedis()
// 创建一个新的日志记录器实例
logger := logrus.New()
// 创建日志文件
logFile, err := os.OpenFile("app.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
logrus.Fatal(err)
panic(err)
}
defer logFile.Close()
// 设置文件日志钩子为日志记录器的输出
logger.SetOutput(logFile)
logger.SetOutput(io.MultiWriter(os.Stdout, logFile))

// 设置 logrus 输出为文件
logrus.SetOutput(logFile)
// 创建一个控制台日志钩子

// 设置 logrus 格式
logrus.SetFormatter(&logrus.TextFormatter{
DisableColors: true,
})
// 设置控制台日志钩子为日志记录器的输出

config.LoadConfig(DEFAULT_CONFIG_PATH)
db.LoadRedis()
Expand Down

0 comments on commit 973b7e7

Please sign in to comment.