Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9205729

Browse files
facchinmcmaglie
authored andcommitted
rethink zip extraction
1 parente3a3096 commit9205729

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

‎sketch_loader.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (s *SketchLoader) Run(ctx *types.Context) error {
8585

8686
logger:=ctx.GetLogger()
8787

88-
if!utils.SliceContains(allSketchFilePaths,sketchLocation) {
88+
if!utils.SliceContains(allSketchFilePaths,sketchLocation)&&!ctx.SketchZipped{
8989
returni18n.ErrorfWithLogger(logger,constants.MSG_CANT_FIND_SKETCH_IN_PATH,sketchLocation,filepath.Dir(sketchLocation))
9090
}
9191

‎utils/utils.go‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,15 @@ func ExtractZip(filePath string, location string) (string, error) {
499499

500500
vardirList []string
501501

502-
for_,f:=ranger.File {
503-
dirList=append(dirList,f.Name)
504-
}
505-
506-
basedir:=findBaseDir(dirList)
507-
508502
for_,f:=ranger.File {
509503
fullname:=filepath.Join(location,strings.Replace(f.Name,"","",-1))
510504
iff.FileInfo().IsDir() {
505+
dirList=append(dirList,fullname)
511506
os.MkdirAll(fullname,0755)
512507
}else {
513508
_,err:=os.Stat(filepath.Dir(fullname))
514509
iferr!=nil {
510+
dirList=append(dirList,filepath.Dir(fullname))
515511
os.MkdirAll(filepath.Dir(fullname),0755)
516512
}
517513
perms:=f.FileInfo().Mode().Perm()
@@ -537,26 +533,23 @@ func ExtractZip(filePath string, location string) (string, error) {
537533
}
538534
}
539535
}
536+
basedir:=filepath.Base(findBaseDir(dirList))
540537
returnfilepath.Join(location,basedir),nil
541538
}
542539

543540
funcfindBaseDir(dirList []string)string {
544541
baseDir:=""
542+
minLen:=256
545543
// https://github.com/backdrop-ops/contrib/issues/55#issuecomment-73814500
546544
dontdiff:= []string{"pax_global_header"}
547-
forindex:=rangedirList {
548-
ifSliceContains(dontdiff,dirList[index]) {
545+
for_,dir:=rangedirList {
546+
ifSliceContains(dontdiff,dir) {
549547
continue
550548
}
551-
candidateBaseDir:=dirList[index]
552-
fori:=index;i<len(dirList);i++ {
553-
if!strings.Contains(dirList[i],candidateBaseDir) {
554-
returnbaseDir
555-
}
556-
}
557-
// avoid setting the candidate if it is the last file
558-
ifdirList[len(dirList)-1]!=candidateBaseDir {
559-
baseDir=candidateBaseDir
549+
//get the shortest string
550+
iflen(dir)<minLen {
551+
baseDir=dir
552+
minLen=len(dir)
560553
}
561554
}
562555
returnbaseDir

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp