-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on Fahed Dorgaa's PR 643 but preserves the file owner information as in `docker cp`. This implementation also avoids mixing up the `archive/tar` pkg and `tar` command. `nerdctl cp -a` is not implemented, as the actual behavior of `docker cp -a` does not seem clearly defined. Tests are added to to cover the conditions listed in https://docs.docker.com/engine/reference/commandline/cp/ TODO (low priority): Support stdio tar balls such as `nerdctl cp - DST` and `nerdctl cp SRC -` Co-authored-by: fahed dorgaa <fahed.dorgaa@gmail.com> Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
- Loading branch information
1 parent
48f189a
commit 2133630
Showing
10 changed files
with
644 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
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 main | ||
|
||
import ( | ||
"errors" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var errFileSpecDoesntMatchFormat = errors.New("filespec must match the canonical format: [container:]file/path") | ||
|
||
func parseCpFileSpec(arg string) (*cpFileSpec, error) { | ||
i := strings.Index(arg, ":") | ||
|
||
// filespec starting with a semicolon is invalid | ||
if i == 0 { | ||
return nil, errFileSpecDoesntMatchFormat | ||
} | ||
|
||
if filepath.IsAbs(arg) { | ||
// Explicit local absolute path, e.g., `C:\foo` or `/foo`. | ||
return &cpFileSpec{ | ||
Container: nil, | ||
Path: arg, | ||
}, nil | ||
} | ||
|
||
parts := strings.SplitN(arg, ":", 2) | ||
|
||
if len(parts) == 1 || strings.HasPrefix(parts[0], ".") { | ||
// Either there's no `:` in the arg | ||
// OR it's an explicit local relative path like `./file:name.txt`. | ||
return &cpFileSpec{ | ||
Path: arg, | ||
}, nil | ||
} | ||
|
||
return &cpFileSpec{ | ||
Container: &parts[0], | ||
Path: parts[1], | ||
}, nil | ||
} | ||
|
||
type cpFileSpec struct { | ||
Container *string | ||
Path string | ||
} | ||
|
||
func cpShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return nil, cobra.ShellCompDirectiveFilterFileExt | ||
} |
Oops, something went wrong.