Skip to content

Commit 7340b4f

Browse files
committed
cmd/sync: add the jfs specific prefix to distinguish business files from internal files
1 parent d98d315 commit 7340b4f

File tree

7 files changed

+12
-13
lines changed

7 files changed

+12
-13
lines changed

cmd/object.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"io"
25-
"math/rand"
2625
"os"
2726
"path"
2827
"runtime"
@@ -139,7 +138,7 @@ func (j *juiceFS) Put(rCtx context.Context, key string, in io.Reader, getters ..
139138
if len(name) > 200 {
140139
name = name[:200]
141140
}
142-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".jfs.%s.tmp.%d", name, rand.Int()))
141+
tmp = object.TmpFilePath(p, name)
143142
defer func() {
144143
if err != nil {
145144
if e := j.jfs.Delete(ctx, tmp); e != 0 {

pkg/object/cifs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"context"
2525
"fmt"
2626
"io"
27-
"math/rand"
2827
"net"
2928
"net/url"
3029
"os"
@@ -237,7 +236,7 @@ func (c *cifsStore) Put(ctx context.Context, key string, in io.Reader, getters .
237236
if len(name) > 200 {
238237
name = name[:200]
239238
}
240-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
239+
tmp = TmpFilePath(p, name)
241240
defer func() {
242241
if err != nil {
243242
_ = conn.share.Remove(tmp)

pkg/object/file.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ import (
2222
"fmt"
2323
"io"
2424
"io/fs"
25-
"math/rand"
2625
"os"
2726
"path"
2827
"path/filepath"
2928
"runtime"
3029
"sort"
31-
"strconv"
3230
"strings"
3331

3432
"github.com/juicedata/juicefs/pkg/utils"
@@ -160,7 +158,7 @@ func (d *filestore) Put(ctx context.Context, key string, in io.Reader, getters .
160158
if len(name) > 200 {
161159
name = name[:200]
162160
}
163-
tmp = filepath.Join(filepath.Dir(p), ".jfs."+name+".tmp"+strconv.Itoa(rand.Int()))
161+
tmp = TmpFilePath(p, name)
164162
defer func() {
165163
if err != nil {
166164
_ = os.Remove(tmp)

pkg/object/hdfs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"fmt"
2727
"io"
2828
"io/fs"
29-
"math/rand"
3029
"os"
3130
"os/user"
3231
"path"
@@ -139,7 +138,7 @@ func (h *hdfsclient) Put(ctx context.Context, key string, in io.Reader, getters
139138
if len(name) > 200 {
140139
name = name[:200]
141140
}
142-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
141+
tmp = TmpFilePath(p, name)
143142
defer func() {
144143
if err != nil {
145144
_ = h.c.Remove(tmp)

pkg/object/nfs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"context"
2525
"fmt"
2626
"io"
27-
"math/rand"
2827
"os"
2928
"os/user"
3029
"path"
@@ -176,7 +175,7 @@ func (n *nfsStore) Put(ctx context.Context, key string, in io.Reader, getters ..
176175
if len(name) > 200 {
177176
name = name[:200]
178177
}
179-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
178+
tmp = TmpFilePath(p, name)
180179
defer func() {
181180
if err != nil {
182181
_ = n.target.Remove(tmp)

pkg/object/object_storage.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23+
"math/rand"
2324
"net/url"
2425
"os"
26+
"path/filepath"
2527
"strconv"
2628
"strings"
2729
"sync"
@@ -315,3 +317,7 @@ func decodeKey(value string, typ *string) (string, error) {
315317
}
316318
return value, nil
317319
}
320+
321+
func TmpFilePath(parent, name string) string {
322+
return filepath.Join(filepath.Dir(parent), ".jfs."+name+".tmp"+strconv.Itoa(rand.Int()))
323+
}

pkg/object/sftp.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"context"
1212
"fmt"
1313
"io"
14-
"math/rand"
1514
"net"
1615
"net/url"
1716
"os"
@@ -236,7 +235,7 @@ func (f *sftpStore) Put(ctx context.Context, key string, in io.Reader, getters .
236235
if len(name) > 200 {
237236
name = name[:200]
238237
}
239-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
238+
tmp = TmpFilePath(p, name)
240239
defer func() {
241240
if err != nil {
242241
_ = c.sftpClient.Remove(tmp)

0 commit comments

Comments
 (0)