Skip to content

Commit

Permalink
feat(marmounter): support cp932 zip
Browse files Browse the repository at this point in the history
  • Loading branch information
rinsuki committed Jan 25, 2024
1 parent e7d4bd5 commit 95cc301
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ there is two part:
* If path starts with this prefix, we wouldn't check overlay directory
* `overlaydir=<dir>`
* Overlay directory path (default: `./overlay`)
* `ziplocale=cp932`
* Specify character set of zip file name (default: UTF-8)
* `commandsfile=<file>`
* Read options from this file (one option per line)
* `preload=<glob>`
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/dgraph-io/ristretto v0.1.1
github.com/klauspost/compress v1.17.4
github.com/winfsp/cgofuse v1.5.1-0.20230130140708-f87f5db493b5
golang.org/x/text v0.14.0
google.golang.org/protobuf v1.32.0
)

Expand All @@ -16,5 +17,5 @@ require (
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
golang.org/x/sys v0.5.0 // indirect
)
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/winfsp/cgofuse v1.5.1-0.20230130140708-f87f5db493b5 h1:jxZvjx8Ve5sOXorZG0KzTxbp0Cr1n3FEegfmyd9br1k=
github.com/winfsp/cgofuse v1.5.1-0.20230130140708-f87f5db493b5/go.mod h1:uxjoF2jEYT3+x+vC2KJddEGdk/LU8pRowXmyVMHSV5I=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 h1:k5II8e6QD8mITdi+okbbmR/cIyEbeXLBhy5Ha4nevyc=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
Expand Down
34 changes: 34 additions & 0 deletions marmounter/archive_read_options.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
package main

import (
"fmt"
"strings"

"github.com/bmatcuk/doublestar"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese"
)

type ArchiveReadOptions struct {
StripPrefix string
AdditionalPrefix string
IncludedGlobs []string
zipLocale string
}

func (o *ArchiveReadOptions) SetZipLocale(locale string) error {
if locale != "cp932" {
return fmt.Errorf("invalid locale: %s", locale)
}

o.zipLocale = locale

return nil
}

func (o *ArchiveReadOptions) ConvertZipFileName(path string) string {
if o.zipLocale == "" {
return path
}

var decoder *encoding.Decoder

if o.zipLocale == "cp932" {
decoder = japanese.ShiftJIS.NewDecoder()
}

decoded, err := decoder.String(path)

if err != nil {
panic(err)
}

return decoded
}

func (o *ArchiveReadOptions) GetFilePath(path string) string {
Expand Down
14 changes: 14 additions & 0 deletions marmounter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ func (fs *MayakashiFS) ParseFile(file string) error {
shouldBreak = false
}

if strings.HasPrefix(file, "ziplocale=") {
zf := strings.SplitN(file, ":", 2)
file = zf[1]
zf = strings.SplitN(zf[0], "=", 2)
locale := zf[1]
if err := options.SetZipLocale(locale); err != nil {
return err
}
shouldBreak = false
}

if strings.HasPrefix(file, "commandsfile=") {
// commands are splitted by line.

Expand Down Expand Up @@ -267,6 +278,9 @@ func (fs *MayakashiFS) parseZipFile(file string, o ArchiveReadOptions) error {
var fileCount int

for _, f := range zf.File {
if f.NonUTF8 {
f.Name = o.ConvertZipFileName(f.Name)
}
origPath := o.GetFilePath(f.Name)
if origPath == "" {
continue
Expand Down

0 comments on commit 95cc301

Please sign in to comment.