Skip to content

Commit

Permalink
fix upload directory
Browse files Browse the repository at this point in the history
  • Loading branch information
orzogc committed Oct 2, 2022
1 parent 8201d08 commit 2e72c8e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cipher/cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (c *RsaCipher) Decrypt(cipherText []byte) ([]byte, error) {
n := big.NewInt(0).SetBytes(text[i*rsaBlockSize : (i+1)*rsaBlockSize])
m := big.NewInt(0).Exp(n, big.NewInt(int64(c.key.publicKey.E)), c.key.publicKey.N)
b := m.Bytes()
index := bytes.IndexByte(b, '\x00')
index := bytes.IndexByte(b, 0x00)
if index < 0 {
return nil, fmt.Errorf("解密失败,找不到解密后的文本")
}
Expand Down
1 change: 1 addition & 0 deletions fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func uploadSHA1(filename, fileSize, totalHash, blockHash string, targetCID uint6
if *verbose {
log.Printf("initupload的链接是:%s", uploadURL)
log.Printf("sig的值是:%s", sig)
log.Printf("token的值是:%s", token)
log.Printf("k_ec的值是:%s", encodedToken)
}

Expand Down
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,22 +575,28 @@ func main() {
files := make([]fileInfo, 0, len(flag.Args()))
cidMap := make(map[string]uint64)
for _, file := range flag.Args() {
file = filepath.Clean(file)
info, err := os.Stat(file)
if err != nil {
log.Printf("获取 %s 的信息出现错误:%v", file, err)
}

if info.IsDir() {
// 上传文件夹
if *recursive {
err = filepath.WalkDir(file, func(path string, d fs.DirEntry, err error) error {
if d == nil {
return fmt.Errorf("获取文件夹 %s 的信息出现错误,取消上传该文件夹:%w", path, err)
}

path = filepath.Clean(path)

if d.IsDir() {
if err != nil {
log.Printf("获取文件夹 %s 的信息出现错误,取消上传该文件夹:%v", path, err)
return fs.SkipDir
}

if path == file {
var filename string
if path == "." {
Expand All @@ -602,19 +608,25 @@ func main() {
} else {
filename = filepath.Base(path)
}

cid, err := createDir(config.CID, filename)
if err != nil {
return err
}

cidMap[path] = cid

return nil
}

pdir := filepath.Dir(path)
if pid, ok := cidMap[pdir]; ok {
cid, err := createDir(pid, d.Name())

if err != nil {
return err
}

cidMap[path] = cid
} else {
return fmt.Errorf("没有创建文件夹 %s ,取消上传 %s", filepath.Base(pdir), path)
Expand All @@ -624,6 +636,7 @@ func main() {
log.Printf("获取文件 %s 的信息出现错误,取消上传该文件:%v", path, err)
return nil
}

pdir := filepath.Dir(path)
if pid, ok := cidMap[pdir]; ok {
files = append(files, fileInfo{
Expand Down
1 change: 1 addition & 0 deletions oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func getURLJSON(url string) (v *fastjson.Value, e error) {
var p fastjson.Parser
v, err = p.ParseBytes(body)
checkErr(err)

return v, nil
}

Expand Down

0 comments on commit 2e72c8e

Please sign in to comment.