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

fix(os/gres): add custom prefix / support for resource packing #3621

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion os/gres/gres_func_zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func doZipPathWriter(srcPath string, zipWriter *zip.Writer, option ...Option) er
} else {
files = []string{absolutePath}
}
headerPrefix := strings.TrimRight(usedOption.Prefix, `\/`)
headerPrefix := usedOption.Prefix
if !(headerPrefix == "/") {
headerPrefix = strings.TrimRight(headerPrefix, `\/`)
}
if headerPrefix != "" && gfile.IsDir(absolutePath) {
headerPrefix += "/"
}
Expand Down
25 changes: 19 additions & 6 deletions os/gres/gres_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ func Test_Pack(t *testing.T) {
t.AssertNil(err)
t.Assert(r.Contains("files/"), true)
})

gtest.C(t, func(t *gtest.T) {
var (
srcPath = gtest.DataPath("files")
data, err = gres.Pack(srcPath, "/")
)
t.AssertNil(err)

r := gres.New()
err = r.Add(string(data))
t.AssertNil(err)
t.Assert(r.Contains("/root/"), true)
})
}

func Test_PackToFile(t *testing.T) {
Expand Down Expand Up @@ -121,7 +134,7 @@ func Test_Unpack(t *testing.T) {
}

func Test_Basic(t *testing.T) {
gres.Dump()
// gres.Dump()
gtest.C(t, func(t *gtest.T) {
t.Assert(gres.Get("none"), nil)
t.Assert(gres.Contains("none"), false)
Expand Down Expand Up @@ -180,7 +193,7 @@ func Test_Basic(t *testing.T) {
}

func Test_Get(t *testing.T) {
gres.Dump()
// gres.Dump()
gtest.C(t, func(t *gtest.T) {
t.AssertNE(gres.Get("dir1/test1"), nil)
})
Expand All @@ -196,7 +209,7 @@ func Test_Get(t *testing.T) {
}

func Test_ScanDir(t *testing.T) {
gres.Dump()
// gres.Dump()
gtest.C(t, func(t *gtest.T) {
path := "dir1"
files := gres.ScanDir(path, "*", false)
Expand All @@ -221,7 +234,7 @@ func Test_ScanDir(t *testing.T) {
}

func Test_ScanDirFile(t *testing.T) {
gres.Dump()
// gres.Dump()
gtest.C(t, func(t *gtest.T) {
path := "dir2"
files := gres.ScanDirFile(path, "*", false)
Expand All @@ -246,7 +259,7 @@ func Test_ScanDirFile(t *testing.T) {
}

func Test_Export(t *testing.T) {
gres.Dump()
// gres.Dump()
gtest.C(t, func(t *gtest.T) {
var (
src = `template-res`
Expand Down Expand Up @@ -312,7 +325,7 @@ func TestFile_Name(t *testing.T) {
}

func TestFile_Export(t *testing.T) {
gres.Dump()
// gres.Dump()
gtest.C(t, func(t *gtest.T) {
var (
src = `template-res`
Expand Down