@@ -499,19 +499,15 @@ func ExtractZip(filePath string, location string) (string, error) {
499499
500500	var  dirList  []string 
501501
502- 	for  _ , f  :=  range  r .File  {
503- 		dirList  =  append (dirList , f .Name )
504- 	}
505- 
506- 	basedir  :=  findBaseDir (dirList )
507- 
508502	for  _ , f  :=  range  r .File  {
509503		fullname  :=  filepath .Join (location , strings .Replace (f .Name , "" , "" , - 1 ))
510504		if  f .FileInfo ().IsDir () {
505+ 			dirList  =  append (dirList , fullname )
511506			os .MkdirAll (fullname , 0755 )
512507		} else  {
513508			_ , err  :=  os .Stat (filepath .Dir (fullname ))
514509			if  err  !=  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	return  filepath .Join (location , basedir ), nil 
541538}
542539
543540func  findBaseDir (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- 	for  index  :=  range  dirList  {
548- 		if  SliceContains (dontdiff , dirList [ index ] ) {
545+ 	for  _ ,  dir  :=  range  dirList  {
546+ 		if  SliceContains (dontdiff , dir ) {
549547			continue 
550548		}
551- 		candidateBaseDir  :=  dirList [index ]
552- 		for  i  :=  index ; i  <  len (dirList ); i ++  {
553- 			if  ! strings .Contains (dirList [i ], candidateBaseDir ) {
554- 				return  baseDir 
555- 			}
556- 		}
557- 		// avoid setting the candidate if it is the last file 
558- 		if  dirList [len (dirList )- 1 ] !=  candidateBaseDir  {
559- 			baseDir  =  candidateBaseDir 
549+ 		//get the shortest string 
550+ 		if  len (dir ) <  minLen  {
551+ 			baseDir  =  dir 
552+ 			minLen  =  len (dir )
560553		}
561554	}
562555	return  baseDir 
0 commit comments