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

clone command fails to copy VM configuration. #1111

Open
jason-dour-e opened this issue Aug 14, 2024 · 1 comment
Open

clone command fails to copy VM configuration. #1111

jason-dour-e opened this issue Aug 14, 2024 · 1 comment

Comments

@jason-dour-e
Copy link

Using colima clone command to move profiles around. While doing so, encountered the following error:

colima clone default clone
INFO[0000] preparing to clone colima...
INFO[0000] cloning virtual machine...
INFO[0029] copying config...
cp: /Users/j/.colima/_lima/colima is a directory (not copied).
FATA[0029] error copying VM config: exit status 1

Looking at the code, it appears the cp command is called on two directories, but without a -r flag to recurse the source directory. This causes the failure above. The code in question is:

if err := cli.Command("cp", from.LimaInstanceDir(), to.LimaInstanceDir()).Run(); err != nil {

Now, in the preceding code, the target directory is created and specific files are copied:

colima/cmd/clone.go

Lines 26 to 52 in 73732ae

{
// verify source profile exists
if stat, err := os.Stat(from.LimaInstanceDir()); err != nil || !stat.IsDir() {
return fmt.Errorf("colima profile '%s' does not exist", from.ShortName)
}
// verify destination profile does not exists
if stat, err := os.Stat(to.LimaInstanceDir()); err == nil && stat.IsDir() {
return fmt.Errorf("colima profile '%s' already exists, delete with `colima delete %s` and try again", to.ShortName, to.ShortName)
}
// copy source to destination
logrus.Info("cloning virtual machine...")
if err := cli.Command("mkdir", "-p", to.LimaInstanceDir()).Run(); err != nil {
return fmt.Errorf("error preparing to copy VM: %w", err)
}
if err := cli.Command("cp",
filepath.Join(from.LimaInstanceDir(), "basedisk"),
filepath.Join(from.LimaInstanceDir(), "diffdisk"),
filepath.Join(from.LimaInstanceDir(), "cidata.iso"),
filepath.Join(from.LimaInstanceDir(), "lima.yaml"),
to.LimaInstanceDir(),
).Run(); err != nil {
return fmt.Errorf("error copying VM: %w", err)
}
}

So a recursive -r flag on the subsequent copy in Line 66 might not be the proper way to fix this, as it would copy for a second time the files copied in lines 26-52.

The second cp could copy specific named files like the prior copy. Or could do a recursive copy but delete any unwanted files such as *.log and *.sock.

I haven't created a PR because I do not have a confirmed way to test the code on my platform (MacOS via Homebrew), but could try if I received some guidance on how and this would speed up a fix.

Thanks,
Jason

@jason-dour-e
Copy link
Author

Meant to include, I ran a cp -r src-dir tgt-dir manually after the clone command failed, and was able to use the cloned profile. So completing the second cp appears to resolve the only failed step in the clone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant