Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
coreospackage
Commits
ed991d13
Commit
ed991d13
authored
7 years ago
by
Ajit Jagtap
Browse files
Options
Downloads
Plain Diff
Merge branch 'ZipWithoutBaseDir_SSS' into 'master'
ZipWithoutBaseDirectory See merge request
!28
parents
ed14dbde
6fa271a0
Branches
Branches containing commit
1 merge request
!28
ZipWithoutBaseDirectory
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
filehelper/fileHelper.go
+70
-0
filehelper/fileHelper.go
with
70 additions
and
0 deletions
filehelper/fileHelper.go
+
70
−
0
View file @
ed991d13
...
...
@@ -146,6 +146,76 @@ func Zip(source, target string) error {
return
err
}
//ZipWithoutBaseDirectory Zip Without Base Directory
func
ZipWithoutBaseDirectory
(
source
,
target
string
)
error
{
source
=
filepath
.
Clean
(
source
)
target
=
filepath
.
Clean
(
target
)
zipfile
,
err
:=
os
.
Create
(
target
)
if
err
!=
nil
{
return
err
}
defer
zipfile
.
Close
()
archive
:=
zip
.
NewWriter
(
zipfile
)
defer
archive
.
Close
()
info
,
err
:=
os
.
Stat
(
source
)
if
err
!=
nil
{
return
err
}
var
baseDir
string
if
info
.
IsDir
()
{
baseDir
=
filepath
.
Base
(
source
)
}
filepath
.
Walk
(
source
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
header
,
err
:=
zip
.
FileInfoHeader
(
info
)
if
err
!=
nil
{
return
err
}
if
baseDir
!=
""
{
header
.
Name
=
strings
.
TrimPrefix
(
path
,
source
)
// Replace all occurances of \\ with /. This is necessary to properly unzip the zip file created on windows system on ubuntu system
header
.
Name
=
strings
.
Replace
(
header
.
Name
,
"
\\
"
,
"/"
,
-
1
)
}
if
info
.
IsDir
()
{
header
.
Name
+=
"/"
}
else
{
header
.
Method
=
zip
.
Deflate
}
writer
,
err
:=
archive
.
CreateHeader
(
header
)
if
err
!=
nil
{
return
err
}
if
info
.
IsDir
()
{
return
nil
}
file
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
err
}
_
,
err
=
io
.
Copy
(
writer
,
file
)
if
err
!=
nil
{
}
file
.
Close
()
return
err
})
return
err
}
//ZipWithSkipFileList This method will skip the file added in skiplist from zip
func
ZipWithSkipFileList
(
source
,
target
string
,
skipFileList
[]
string
)
error
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets