" if the tar is comprised of single file or directory, rename that file to the desired location" maybe not good idea #5864
motocoder-cn
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
func unpack(srcPath string, destPath string, decompressor func(string, string) error) error { // first extract the tar into a temporary dir tmpDir := destPath + ".tmpdir" err := os.MkdirAll(tmpDir, os.ModePerm) if err != nil { return errors.InternalWrapError(err) } if decompressor != nil { if err = decompressor(srcPath, tmpDir); err != nil { return err } } // next, decide how we wish to rename the file/dir // to the destination path. files, err := ioutil.ReadDir(tmpDir) if err != nil { return errors.InternalWrapError(err) } if len(files) == 1 { // if the tar is comprised of single file or directory, // rename that file to the desired location filePath := path.Join(tmpDir, files[0].Name()) err = os.Rename(filePath, destPath) if err != nil { return errors.InternalWrapError(err) } err = os.Remove(tmpDir) if err != nil { return errors.InternalWrapError(err) } } else { // the tar extracted into multiple files. In this case, // just rename the temp directory to the dest path err = os.Rename(tmpDir, destPath) if err != nil { return errors.InternalWrapError(err) } } return nil }
--code
then first level "code" will deleted by init container
2.but when input artifact is a tar.gz with inner layout like:
--code
then first level "code" will not deleted by init container
this different action cause some confuse, may not a good idea?
Beta Was this translation helpful? Give feedback.
All reactions