-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feature: 上传时默认忽略隐藏的文件 - 用户上传目录时,目录中包含的 . 开头的文件默认会被忽略 - 用户可以使用 --all 参数 强制上传所以文件 * 忽略windows下的隐藏文件 - 增加对windows系统下隐藏文件忽略的支持 * 上传隐藏目录触发提示 如果上传的是目录,并且是隐藏的目录,没有使用 `-all` 参数则触发提示 * chore: 增加忽略文件的测试用例
- Loading branch information
Showing
8 changed files
with
189 additions
and
28 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,10 @@ | ||
package fsutil | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// 判断文件是否是 . 开头的 | ||
func hasDotPrefix(filename string) bool { | ||
return strings.HasPrefix(filename, ".") | ||
} |
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,13 @@ | ||
//go:build linux || darwin | ||
|
||
package fsutil | ||
|
||
import ( | ||
"io/fs" | ||
"path/filepath" | ||
) | ||
|
||
// 判断文件是否是需要忽略的文件 | ||
func IsIgnoreFile(path string, fileInfo fs.FileInfo) bool { | ||
return hasDotPrefix(filepath.Base(path)) | ||
} |
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,23 @@ | ||
//go:build windows | ||
|
||
package fsutil | ||
|
||
import ( | ||
"io/fs" | ||
"path/filepath" | ||
"syscall" | ||
) | ||
|
||
// 判断文件是否是需要忽略的文件 | ||
func IsIgnoreFile(path string, fileInfo fs.FileInfo) bool { | ||
for hasDotPrefix(filepath.Base(path)) { | ||
return true | ||
} | ||
|
||
underlyingData := fileInfo.Sys().(*syscall.Win32FileAttributeData) | ||
if underlyingData != nil { | ||
return underlyingData.FileAttributes&syscall.FILE_ATTRIBUTE_HIDDEN != 0 | ||
} | ||
|
||
return false | ||
} |
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,99 @@ | ||
package upx | ||
|
||
import ( | ||
"io/ioutil" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Ls(up string) ([]string, error) { | ||
b, err := Upx("ls", up) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ups = make([]string, 0) | ||
output := strings.TrimRight(string(b), "\n") | ||
for _, line := range strings.Split(output, "\n") { | ||
items := strings.Split(line, " ") | ||
ups = append(ups, items[len(items)-1]) | ||
} | ||
return ups, nil | ||
} | ||
|
||
func TestPutIgnore(t *testing.T) { | ||
SetUp() | ||
defer TearDown() | ||
|
||
upRootPath := path.Join(ROOT, "iginore") | ||
Upx("mkdir", upRootPath) | ||
|
||
localRootPath, err := ioutil.TempDir("", "test") | ||
assert.NoError(t, err) | ||
localRootName := filepath.Base(localRootPath) | ||
|
||
CreateFile(path.Join(localRootPath, "FILE1")) | ||
CreateFile(path.Join(localRootPath, "FILE2")) | ||
CreateFile(path.Join(localRootPath, ".FILE3")) | ||
CreateFile(path.Join(localRootPath, ".FILES/FILE")) | ||
|
||
// 上传文件夹 | ||
// 不包含隐藏的文件,所以只有FILE1和FILE2 | ||
Upx("put", localRootPath, upRootPath) | ||
files, err := Ls(path.Join(upRootPath, localRootName)) | ||
|
||
assert.NoError(t, err) | ||
assert.Len(t, files, 2) | ||
assert.ElementsMatch( | ||
t, | ||
files, | ||
[]string{"FILE1", "FILE2"}, | ||
) | ||
|
||
// 上传隐藏的文件夹, 无all,上传失效 | ||
Upx( | ||
"put", | ||
path.Join(localRootPath, ".FILES"), | ||
path.Join(upRootPath, localRootName, ".FILES"), | ||
) | ||
files, err = Ls(path.Join(upRootPath, localRootName)) | ||
assert.NoError(t, err) | ||
|
||
assert.Len(t, files, 2) | ||
assert.ElementsMatch( | ||
t, | ||
files, | ||
[]string{"FILE1", "FILE2"}, | ||
) | ||
|
||
// 上传隐藏的文件夹, 有all,上传成功 | ||
Upx( | ||
"put", | ||
"-all", | ||
path.Join(localRootPath, ".FILES"), | ||
path.Join(upRootPath, localRootName, ".FILES"), | ||
) | ||
files, err = Ls(path.Join(upRootPath, localRootName)) | ||
assert.NoError(t, err) | ||
assert.Len(t, files, 3) | ||
assert.ElementsMatch( | ||
t, | ||
files, | ||
[]string{"FILE1", "FILE2", ".FILES"}, | ||
) | ||
|
||
// 上传所有文件 | ||
Upx("put", "-all", localRootPath, upRootPath) | ||
files, err = Ls(path.Join(upRootPath, localRootName)) | ||
assert.NoError(t, err) | ||
assert.Len(t, files, 4) | ||
assert.ElementsMatch( | ||
t, | ||
files, | ||
[]string{"FILE1", "FILE2", ".FILE3", ".FILES"}, | ||
) | ||
} |
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