Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/clone: add the clone subcommand #3279

Merged
merged 36 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
796d529
add clone cmd
zhijian-pro Feb 27, 2023
5c7cbee
support hardlink
zhijian-pro Mar 2, 2023
8d8c478
1. concurrent clone
zhijian-pro Mar 5, 2023
eefca0e
fix windows build
zhijian-pro Mar 5, 2023
fa2929a
1. fix redis cluster test
zhijian-pro Mar 6, 2023
dc70bc8
fix windows build
zhijian-pro Mar 6, 2023
5738af2
fix build
zhijian-pro Mar 6, 2023
842dab8
add a progress bar display for the "clone" command
zhijian-pro Mar 6, 2023
1e0a0ac
fix windows build
zhijian-pro Mar 6, 2023
51250f2
fix test
zhijian-pro Mar 7, 2023
870d31f
use uniform errors
zhijian-pro Mar 9, 2023
e709993
fix dstParent nlink and improve test
zhijian-pro Mar 9, 2023
f80051a
remove concurrent
zhijian-pro Mar 10, 2023
fc23e82
adjust flag
zhijian-pro Mar 12, 2023
0d8c662
add concurrent
zhijian-pro Mar 12, 2023
f39a43c
refactor
zhijian-pro Mar 13, 2023
2104214
fix windows build
zhijian-pro Mar 13, 2023
3b02c5c
The clone command supports the SQL engine
zhijian-pro Mar 15, 2023
f9842b3
The clone command supports the tkv engine
zhijian-pro Mar 15, 2023
0412059
fix tikv edge check
zhijian-pro Mar 16, 2023
fc82245
add skipCheckTrash flag
zhijian-pro Mar 17, 2023
81a1382
1. use pointers to pass attr
zhijian-pro Mar 17, 2023
1c336f6
1. fix clone xattr
zhijian-pro Mar 17, 2023
2492fbc
refactor test
zhijian-pro Mar 17, 2023
330f71d
1. check quota
zhijian-pro Mar 17, 2023
dafcc4f
check entry xattr
zhijian-pro Mar 18, 2023
be532bd
Merge branch 'main' into add_clone_cmd
zhijian-pro Mar 18, 2023
5c8d085
merge main
zhijian-pro Mar 18, 2023
1b4569a
fix
zhijian-pro Mar 18, 2023
2c48b25
fix check quota and align4K space
zhijian-pro Mar 20, 2023
8491103
del clone dstNode
zhijian-pro Mar 20, 2023
0a0b3a3
adjust
zhijian-pro Mar 20, 2023
b913a97
fix deadlock
zhijian-pro Mar 21, 2023
7de3a3b
Merge branch 'main' into add_clone_cmd
zhijian-pro Mar 22, 2023
f40e920
don't depend on all sql engines
davies Mar 22, 2023
748346e
fix pg
davies Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cmd/clone_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* JuiceFS, Copyright 2023 Juicedata, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cmd

import (
"testing"
)

func TestClone(t *testing.T) {
t.SkipNow()
// todo

}
118 changes: 118 additions & 0 deletions cmd/clone_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//go:build !windows

/*
* JuiceFS, Copyright 2023 Juicedata, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cmd

import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"syscall"

"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/urfave/cli/v2"
)

func cmdClone() *cli.Command {
return &cli.Command{
Name: "clone",
Action: clone,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "cp",
zhijian-pro marked this conversation as resolved.
Show resolved Hide resolved
Usage: "create files with current uid,gid,umask (like 'cp')"},
},
Category: "TOOL",
Description: `This command can clone a file or directory without copying the underlying data.`,
}
}

func clone(ctx *cli.Context) error {
setup(ctx, 2)
if runtime.GOOS == "windows" {
logger.Infof("Windows is not supported")
return nil
}
srcPath := ctx.Args().Get(0)
srcAbsPath, err := filepath.Abs(srcPath)
if err != nil {
return fmt.Errorf("abs of %s: %s", srcPath, err)
}
srcParent := filepath.Dir(srcAbsPath)
srcIno, err := utils.GetFileInode(srcPath)
if err != nil {
return fmt.Errorf("lookup inode for %s: %s", srcPath, err)
}
dst := ctx.Args().Get(1)
if strings.HasSuffix(dst, "/") {
dst = filepath.Join(dst, filepath.Base(srcPath))
}
if _, err := os.Stat(dst); err == nil || !os.IsNotExist(err) {
return fmt.Errorf("%s already exists", dst)
}
dstAbsPath, err := filepath.Abs(dst)
if err != nil {
return fmt.Errorf("abs of %s: %s", dstAbsPath, err)
}
dstParent := filepath.Dir(dstAbsPath)
dstName := filepath.Base(dstAbsPath)
dstParentIno, err := utils.GetFileInode(dstParent)
if err != nil {
return fmt.Errorf("lookup inode for %s: %s", dstParent, err)
}
var smode uint8
var umask int
if ctx.Bool("cp") {
smode |= meta.CLONE_MODE_CPLIKE_ATTR
umask = syscall.Umask(0)
syscall.Umask(umask)
}
wb := utils.NewBuffer(4 + 4 + 8 + 8 + 1 + uint32(len(dstName)) + 4 + 4 + 2 + 1)
wb.Put32(meta.Clone)
wb.Put32(8 + +8 + 1 + uint32(len(dstName)) + 4 + 4 + 2 + 1)
zhijian-pro marked this conversation as resolved.
Show resolved Hide resolved
wb.Put64(srcIno)
wb.Put64(dstParentIno)
wb.Put8(uint8(len(dstName)))
wb.Put([]byte(dstName))
wb.Put32(uint32(os.Getuid()))
wb.Put32(uint32(os.Getgid()))
wb.Put16(uint16(umask))
wb.Put8(smode)
f := openController(srcParent)
if f == nil {
return fmt.Errorf("%s is not inside JuiceFS", srcPath)
}
defer f.Close()
if _, err = f.Write(wb.Bytes()); err != nil {
return fmt.Errorf("write message: %s", err)
}

progress := utils.NewProgress(false)
defer progress.Done()
bar := progress.AddCountBar("Cloning entries", 0)
if errno := readProgress(f, func(count uint64, total uint64) {
bar.SetTotal(int64(total))
bar.SetCurrent(int64(count))
}); errno != 0 {
return fmt.Errorf("clone failed: %v", errno)
}
return nil
}
33 changes: 33 additions & 0 deletions cmd/clone_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* JuiceFS, Copyright 2023 Juicedata, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cmd

import (
"github.com/juicedata/juicefs/pkg/utils"
"github.com/urfave/cli/v2"
)

func cmdClone() *cli.Command {
return &cli.Command{
Name: "clone",
Category: "TOOL",
Description: `This command is not supported on windows.`,
Action: func(context *cli.Context) error {
return utils.ENOTSUP
},
}
}
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func Main(args []string) error {
cmdRmr(),
cmdSync(),
cmdDebug(),
cmdClone(),
},
}

Expand Down
Loading