Commit 834df8a7 authored by Sandeep S. Shewalkar's avatar Sandeep S. Shewalkar
Browse files

File helper changes

FileAvailabilityCheck added while Unzipping the zip files. If directory is not available, directory will be created 
parent cce57481
Branches
1 merge request!26File helper changes
Showing with 10 additions and 4 deletions
......@@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
......@@ -239,10 +240,15 @@ func Unzip(archive, target string) error {
}
for _, file := range reader.File {
path := filepath.Join(target, file.Name)
if file.FileInfo().IsDir() {
filePath := filepath.Join(target, file.Name)
parentPath := path.Dir(CleanPath(filePath))
if !FileAvailabilityCheck(parentPath) {
CreateDirectoryRecursive(parentPath)
}
os.MkdirAll(path, file.Mode())
if file.FileInfo().IsDir() {
os.MkdirAll(filePath, file.Mode())
continue
}
......@@ -252,7 +258,7 @@ func Unzip(archive, target string) error {
return openError
}
targetFile, targetOpenError := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
targetFile, targetOpenError := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
if targetOpenError != nil {
logginghelper.LogError(targetOpenError)
return targetOpenError
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment