Ignore hidden file when creating archive file (#1450)
This commit is contained in:
@@ -85,7 +85,7 @@ func CreateArchive(client *client.Client, includeFiles []string, noZip bool, ins
|
||||
}
|
||||
|
||||
path := filepath.Join(rootDir, path)
|
||||
files, err := utils.FindAllGlobs([]string{path})
|
||||
files, err := utils.FindAllGlobs(path)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, errors.Wrap(err, "error finding all globs"))
|
||||
continue
|
||||
@@ -198,7 +198,7 @@ func makeArchiveFile(archiveNameHint string, archiveInput []string, noZip bool)
|
||||
archiveName := archiveName(archiveNameHint, archiveInput)
|
||||
|
||||
// Get files from inputs as number of files decide next steps
|
||||
files, err := utils.FindAllGlobs(archiveInput)
|
||||
files, err := utils.FindAllGlobs(archiveInput...)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error finding all globs")
|
||||
}
|
||||
|
||||
@@ -427,13 +427,13 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
|
||||
files = append(files, aus.IncludeGlobs[0])
|
||||
} else {
|
||||
for _, relativeGlob := range aus.IncludeGlobs {
|
||||
absGlob := rootDir + "/" + relativeGlob
|
||||
f, err := filepath.Glob(absGlob)
|
||||
absGlob := filepath.Join(rootDir, relativeGlob)
|
||||
console.Verbose(2, "try to find globs in path '%v'", absGlob)
|
||||
fs, err := utils.FindAllGlobs(absGlob)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Invalid glob in archive %v: %v", aus.Name, relativeGlob)
|
||||
}
|
||||
files = append(files, f...)
|
||||
// xxx handle excludeGlobs here
|
||||
files = append(files, fs...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-8
@@ -21,7 +21,6 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@@ -33,10 +32,12 @@ import (
|
||||
"github.com/mholt/archiver"
|
||||
"github.com/pkg/errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
)
|
||||
|
||||
func UrlForFunction(name, namespace string) string {
|
||||
@@ -102,21 +103,34 @@ func GetTempDir() (string, error) {
|
||||
return dir, err
|
||||
}
|
||||
|
||||
// FindAllGlobs returns a list of globs of input list.
|
||||
func FindAllGlobs(inputList []string) ([]string, error) {
|
||||
// FindAllGlobs ignores all hidden files and returns a list of globs of input list.
|
||||
func FindAllGlobs(paths ...string) ([]string, error) {
|
||||
files := make([]string, 0)
|
||||
for _, glob := range inputList {
|
||||
f, err := filepath.Glob(glob)
|
||||
for _, p := range paths {
|
||||
// use absolute path to find files
|
||||
path, err := filepath.Abs(p)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("invalid glob %v: %v", glob, err)
|
||||
return nil, errors.Wrapf(err, "error getting absolute path of path '%v'", p)
|
||||
}
|
||||
globs, err := filepath.Glob(path)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("invalid glob %v: %v", path, err)
|
||||
}
|
||||
for _, f := range globs {
|
||||
// ignore hidden file.
|
||||
if strings.HasPrefix(filepath.Base(f), ".") {
|
||||
console.Verbose(2, "Ignore hidden file '%v'", f)
|
||||
continue
|
||||
}
|
||||
files = append(files, f)
|
||||
// xxx handle excludeGlobs here
|
||||
}
|
||||
files = append(files, f...)
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func MakeZipArchive(targetName string, globs ...string) (string, error) {
|
||||
files, err := FindAllGlobs(globs)
|
||||
files, err := FindAllGlobs(globs...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -532,6 +532,7 @@ run_all_tests() {
|
||||
$ROOT/test/tests/test_router_cache_invalidation.sh \
|
||||
$ROOT/test/tests/test_specs/test_spec.sh \
|
||||
$ROOT/test/tests/test_specs/test_spec_multifile.sh \
|
||||
$ROOT/test/tests/test_specs/test_ignore_hidden_file.sh \
|
||||
$ROOT/test/tests/test_specs/test_spec_merge/test_spec_merge.sh \
|
||||
$ROOT/test/tests/test_environments/test_tensorflow_serving_env.sh \
|
||||
$ROOT/test/tests/test_environments/test_go_env.sh \
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
source $(dirname $0)/../../utils.sh
|
||||
ROOT=` realpath $(dirname $0)/../../../`
|
||||
TEST_ID=$(generate_test_id)
|
||||
|
||||
cleanup() {
|
||||
log "Cleaning up..."
|
||||
fission spec destroy || true
|
||||
rm -rf document specs
|
||||
rm -rf ${TEST_ID}
|
||||
popd
|
||||
}
|
||||
|
||||
if [ -z "${TEST_NOCLEANUP:-}" ]; then
|
||||
trap cleanup EXIT
|
||||
else
|
||||
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
|
||||
fi
|
||||
|
||||
tmp_dir="/tmp/test-$TEST_ID"
|
||||
mkdir -p $tmp_dir
|
||||
|
||||
pushd $tmp_dir
|
||||
|
||||
mkdir -p document
|
||||
cp $ROOT/examples/nodejs/hello.js document/h1.js
|
||||
cp $ROOT/examples/nodejs/hello.js document/h2.js
|
||||
|
||||
log "Create hidden file"
|
||||
touch document/.im_invisible
|
||||
|
||||
log "Create specs"
|
||||
fission spec init
|
||||
fission pkg list
|
||||
|
||||
#fission env create --name nodejs --image fission/node-env --period 5 --version 2 --spec
|
||||
fission pkg create --name nodejs --env nodejs --deploy "document/*" --spec
|
||||
|
||||
log "Apply specs"
|
||||
fission --verbosity 2 spec apply
|
||||
|
||||
mkdir ${TEST_ID}
|
||||
fission pkg getdeploy --name nodejs > ${TEST_ID}/a.zip
|
||||
unzip ${TEST_ID}/a.zip -d ${TEST_ID}/
|
||||
|
||||
log "Check whether hidden file exists"
|
||||
if [ -f ${TEST_ID}/.im_invisible ];
|
||||
then
|
||||
log "Found hidden file"
|
||||
ls -al ${TEST_ID}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Check file amount"
|
||||
fileamount=$(ls -al ${TEST_ID} | grep -v total | wc -l)
|
||||
if [ ! ${fileamount} -eq 5 ];
|
||||
then
|
||||
log "File amount incorrect, expect 5"
|
||||
ls -al ${TEST_ID}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Test PASSED"
|
||||
Reference in New Issue
Block a user