Skip to content

Commit 4d916ae

Browse files
authored
os/gres: fix #3611 add custom prefix / support for resource packing (#3621)
1 parent 59a775a commit 4d916ae

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

os/gres/gres_func_zip.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ func doZipPathWriter(srcPath string, zipWriter *zip.Writer, option ...Option) er
6262
} else {
6363
files = []string{absolutePath}
6464
}
65-
headerPrefix := strings.TrimRight(usedOption.Prefix, `\/`)
65+
headerPrefix := usedOption.Prefix
66+
if !(headerPrefix == "/") {
67+
headerPrefix = strings.TrimRight(headerPrefix, `\/`)
68+
}
6669
if headerPrefix != "" && gfile.IsDir(absolutePath) {
6770
headerPrefix += "/"
6871
}

os/gres/gres_z_unit_test.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ func Test_Pack(t *testing.T) {
6363
t.AssertNil(err)
6464
t.Assert(r.Contains("files/"), true)
6565
})
66+
67+
gtest.C(t, func(t *gtest.T) {
68+
var (
69+
srcPath = gtest.DataPath("files")
70+
data, err = gres.Pack(srcPath, "/")
71+
)
72+
t.AssertNil(err)
73+
74+
r := gres.New()
75+
err = r.Add(string(data))
76+
t.AssertNil(err)
77+
t.Assert(r.Contains("/root/"), true)
78+
})
6679
}
6780

6881
func Test_PackToFile(t *testing.T) {
@@ -121,7 +134,7 @@ func Test_Unpack(t *testing.T) {
121134
}
122135

123136
func Test_Basic(t *testing.T) {
124-
gres.Dump()
137+
// gres.Dump()
125138
gtest.C(t, func(t *gtest.T) {
126139
t.Assert(gres.Get("none"), nil)
127140
t.Assert(gres.Contains("none"), false)
@@ -180,7 +193,7 @@ func Test_Basic(t *testing.T) {
180193
}
181194

182195
func Test_Get(t *testing.T) {
183-
gres.Dump()
196+
// gres.Dump()
184197
gtest.C(t, func(t *gtest.T) {
185198
t.AssertNE(gres.Get("dir1/test1"), nil)
186199
})
@@ -196,7 +209,7 @@ func Test_Get(t *testing.T) {
196209
}
197210

198211
func Test_ScanDir(t *testing.T) {
199-
gres.Dump()
212+
// gres.Dump()
200213
gtest.C(t, func(t *gtest.T) {
201214
path := "dir1"
202215
files := gres.ScanDir(path, "*", false)
@@ -221,7 +234,7 @@ func Test_ScanDir(t *testing.T) {
221234
}
222235

223236
func Test_ScanDirFile(t *testing.T) {
224-
gres.Dump()
237+
// gres.Dump()
225238
gtest.C(t, func(t *gtest.T) {
226239
path := "dir2"
227240
files := gres.ScanDirFile(path, "*", false)
@@ -246,7 +259,7 @@ func Test_ScanDirFile(t *testing.T) {
246259
}
247260

248261
func Test_Export(t *testing.T) {
249-
gres.Dump()
262+
// gres.Dump()
250263
gtest.C(t, func(t *gtest.T) {
251264
var (
252265
src = `template-res`
@@ -312,7 +325,7 @@ func TestFile_Name(t *testing.T) {
312325
}
313326

314327
func TestFile_Export(t *testing.T) {
315-
gres.Dump()
328+
// gres.Dump()
316329
gtest.C(t, func(t *gtest.T) {
317330
var (
318331
src = `template-res`

0 commit comments

Comments
 (0)