mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-02 21:27:15 +08:00
fix relative path error for sync command to fix issue #135
This commit is contained in:
parent
4e7545e6e6
commit
08c9d58ef8
@ -166,16 +166,16 @@ priority - 优先级,只对双向同步备份模式有效。选项支持三种
|
||||
mode := c.String("mode")
|
||||
if localDir != "" && panDir != "" {
|
||||
// make path absolute
|
||||
if !utils.IsAbsPath(localDir) {
|
||||
if !utils.IsLocalAbsPath(localDir) {
|
||||
pwd, _ := os.Getwd()
|
||||
localDir = path.Join(pwd, path.Clean(localDir))
|
||||
}
|
||||
panDir = activeUser.PathJoin(activeUser.ActiveDriveId, panDir)
|
||||
if !utils.IsAbsPath(localDir) {
|
||||
if !utils.IsLocalAbsPath(localDir) {
|
||||
fmt.Println("本地目录请指定绝对路径")
|
||||
return nil
|
||||
}
|
||||
if !path.IsAbs(panDir) {
|
||||
if !utils.IsPanAbsPath(panDir) {
|
||||
fmt.Println("网盘目录请指定绝对路径")
|
||||
return nil
|
||||
}
|
||||
|
@ -390,6 +390,7 @@ func (f *FileActionTask) uploadFile(ctx context.Context) error {
|
||||
} else {
|
||||
efi, apierr := f.panClient.FileInfoByPath(f.syncItem.DriveId, targetPanFilePath)
|
||||
if apierr != nil && apierr.Code != apierror.ApiCodeFileNotFoundCode {
|
||||
logger.Verbosef("上传文件错误: %s\n", apierr.String())
|
||||
return apierr
|
||||
}
|
||||
if efi != nil && efi.FileId != "" {
|
||||
|
@ -134,6 +134,16 @@ func (m *SyncTaskManager) Start(tasks []*SyncTask) (bool, error) {
|
||||
if len(task.Id) == 0 {
|
||||
task.Id = utils.UuidStr()
|
||||
}
|
||||
// check pan path
|
||||
if !utils.IsPanAbsPath(task.PanFolderPath) {
|
||||
task.PanFolderPath = "/" + task.PanFolderPath
|
||||
}
|
||||
|
||||
// check local path
|
||||
if !utils.IsLocalAbsPath(task.LocalFolderPath) {
|
||||
fmt.Println("任务启动失败,本地路径不是绝对路径: ", task.LocalFolderPath)
|
||||
continue
|
||||
}
|
||||
task.panUser = m.PanUser
|
||||
task.DriveId = m.DriveId
|
||||
task.syncDbFolderPath = m.SyncConfigFolderPath
|
||||
|
@ -235,8 +235,8 @@ func Md5Str(text string) string {
|
||||
return strings.ToLower(sb.String())
|
||||
}
|
||||
|
||||
// IsAbsPath 是否是绝对路径
|
||||
func IsAbsPath(filePath string) bool {
|
||||
// IsLocalAbsPath 是否是本地绝对路径
|
||||
func IsLocalAbsPath(filePath string) bool {
|
||||
if runtime.GOOS == "windows" {
|
||||
// 是否是windows路径
|
||||
matched, _ := regexp.MatchString("^([a-zA-Z]:)", filePath)
|
||||
@ -249,3 +249,8 @@ func IsAbsPath(filePath string) bool {
|
||||
return path.IsAbs(filePath)
|
||||
}
|
||||
}
|
||||
|
||||
// IsPanAbsPath 是否是云盘绝对路径
|
||||
func IsPanAbsPath(filePath string) bool {
|
||||
return path.IsAbs(filePath)
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ func TestParseTimeStr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIsAbsPath_ReturnTrue(t *testing.T) {
|
||||
fmt.Println(IsAbsPath("D:\\my\\folder\\test"))
|
||||
fmt.Println(IsLocalAbsPath("D:\\my\\folder\\test"))
|
||||
}
|
||||
|
||||
func TestIsAbsPath_ReturnFalse(t *testing.T) {
|
||||
fmt.Println(IsAbsPath("my\\folder\\test"))
|
||||
fmt.Println(IsLocalAbsPath("my\\folder\\test"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user