Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
vMap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open source
vMap
Commits
0b83dc2d
Commit
0b83dc2d
authored
Dec 12, 2018
by
Anthony Borghi
Browse files
Options
Downloads
Patches
Plain Diff
Retouche fonctions de gestion d'archive après test
parent
1af34c8f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
vas/rest/class/vmlib/files/Files_common.class.inc
+13
-18
13 additions, 18 deletions
vas/rest/class/vmlib/files/Files_common.class.inc
vas/rest/class/vmlib/files/S3_files.class.inc
+15
-4
15 additions, 4 deletions
vas/rest/class/vmlib/files/S3_files.class.inc
with
28 additions
and
22 deletions
vas/rest/class/vmlib/files/Files_common.class.inc
+
13
−
18
View file @
0b83dc2d
...
@@ -41,29 +41,24 @@ abstract class Files_common {
...
@@ -41,29 +41,24 @@ abstract class Files_common {
*@return boolean true if it's ok, false else.
*@return boolean true if it's ok, false else.
*/
*/
protected
function
clearDir
(
$sDirPath
){
protected
function
clearDir
(
$sDirPath
){
$ouverture
=
@
opendir
(
$sDirPath
);
if
(
!
is_dir
(
$sDirPath
))
if
(
!
$ouverture
)
return
false
;
return
;
while
(
$sFichier
=
readdir
(
$ouverture
))
{
if
(
$sFichier
==
'.'
||
$sFichier
==
'..'
)
$aContent
=
array_diff
(
scandir
(
$sDirPath
),
array
(
"."
,
".."
));
continue
;
if
(
$this
->
is_dir
(
$sDirPath
.
"/"
.
$sFichier
))
{
foreach
(
$aContent
as
$sFichier
)
{
$bCleared
=
$this
->
clearDir
(
$sDirPath
.
"/"
.
$sFichier
);
$sPath
=
$sDirPath
.
"/"
.
$sFichier
;
if
(
!
$bCleared
)
if
(
is_dir
(
$sPath
))
{
if
(
!
Files_common
::
clearDir
(
$sPath
)){
return
false
;
return
false
;
}
}
else
{
}
else
{
$bCleared
=
@
unlink
(
$sDirPath
.
"/"
.
$sFichier
);
if
(
!
unlink
(
$sPath
)){
if
(
!
$bCleared
)
return
false
;
return
false
;
}
}
}
}
closedir
(
$ouverture
);
}
$bCleared
=
@
rmdir
(
$sDirPath
);
return
rmdir
(
$sDirPath
);
if
(
!
$bCleared
)
return
false
;
return
true
;
}
}
/**
/**
*Creates a compressed zip file
*Creates a compressed zip file
...
...
This diff is collapsed.
Click to expand it.
vas/rest/class/vmlib/files/S3_files.class.inc
+
15
−
4
View file @
0b83dc2d
...
@@ -693,6 +693,13 @@ class S3_files extends Files_common implements Files{
...
@@ -693,6 +693,13 @@ class S3_files extends Files_common implements Files{
public
function
copyDirDistantToLocal
(
$sSourceFilePath
,
$sDestFilePath
){
public
function
copyDirDistantToLocal
(
$sSourceFilePath
,
$sDestFilePath
){
list
(
$sBucket
,
$sPrefix
)
=
$this
->
getBucketConst
();
list
(
$sBucket
,
$sPrefix
)
=
$this
->
getBucketConst
();
$sSourcePrefix
=
str_replace
(
$this
->
oProperties
[
"vas_home"
],
$sPrefix
,
$sSourceFilePath
);
$sSourcePrefix
=
str_replace
(
$this
->
oProperties
[
"vas_home"
],
$sPrefix
,
$sSourceFilePath
);
if
(
substr
(
$sSourcePrefix
,
-
1
)
!==
"/"
){
$sSourcePrefix
.
=
"/"
;
}
if
(
substr
(
$sDestFilePath
,
-
1
)
!==
"/"
){
$sDestFilePath
.
=
"/"
;
}
try
{
try
{
$aList
=
$this
->
oS3Client
->
listObjectsV2
(
array
(
$aList
=
$this
->
oS3Client
->
listObjectsV2
(
array
(
'Bucket'
=>
$sBucket
,
'Bucket'
=>
$sBucket
,
...
@@ -760,8 +767,7 @@ class S3_files extends Files_common implements Files{
...
@@ -760,8 +767,7 @@ class S3_files extends Files_common implements Files{
// get all file match with prefix $sFolder in the same arborescence
// get all file match with prefix $sFolder in the same arborescence
if
(
$this
->
copyDirDistantToLocal
(
$sFolder
,
$sPath
)){
if
(
$this
->
copyDirDistantToLocal
(
$sFolder
,
$sPath
)){
// create zip in local
// create zip in local
$bReturn
=
parent
::
createZip
(
$sPath
,
$sPath
.
".zip"
,
$sExtensionToExclude
,
$sPassword
,
$bDeleteFiles
);
if
(
parent
::
createZip
(
$sPath
,
$sPath
.
".zip"
,
$sExtensionToExclude
,
$sPassword
,
$bDeleteFiles
)){
if
(
$bReturn
){
// put result on s3
// put result on s3
$this
->
copyLocalToDistant
(
$sPath
.
".zip"
,
$sDestination
);
$this
->
copyLocalToDistant
(
$sPath
.
".zip"
,
$sDestination
);
// if deletes file cleardir
// if deletes file cleardir
...
@@ -780,6 +786,7 @@ class S3_files extends Files_common implements Files{
...
@@ -780,6 +786,7 @@ class S3_files extends Files_common implements Files{
writeToErrorLog
(
"This prefix not match on s3 : "
.
$sFolder
);
writeToErrorLog
(
"This prefix not match on s3 : "
.
$sFolder
);
return
false
;
return
false
;
}
}
return
true
;
}
}
/**
/**
*copy a directory and it content.
*copy a directory and it content.
...
@@ -790,9 +797,9 @@ class S3_files extends Files_common implements Files{
...
@@ -790,9 +797,9 @@ class S3_files extends Files_common implements Files{
public
function
unZip
(
$sZipFile
,
$sDestination
){
public
function
unZip
(
$sZipFile
,
$sDestination
){
$sPath
=
$this
->
oProperties
[
'extract_dir'
]
.
"/"
.
getUniqRandomId
();
$sPath
=
$this
->
oProperties
[
'extract_dir'
]
.
"/"
.
getUniqRandomId
();
// get zip file on S3
// get zip file on S3
$breturn
=
$this
->
copyDistantToLocal
(
$sZipFile
,
$sPath
.
".zip"
);
if
(
$this
->
copyDistantToLocal
(
$sZipFile
,
$sPath
.
".zip"
)){
if
(
$bReturn
){
// unzip in local
// unzip in local
mkdir
(
$sPath
,
0777
,
true
);
if
(
parent
::
unZip
(
$sPath
.
".zip"
,
$sPath
)){
if
(
parent
::
unZip
(
$sPath
.
".zip"
,
$sPath
)){
// envoi sur s3
// envoi sur s3
$this
->
copyDirLocalToDistant
(
$sPath
,
$sDestination
);
$this
->
copyDirLocalToDistant
(
$sPath
,
$sDestination
);
...
@@ -801,11 +808,14 @@ class S3_files extends Files_common implements Files{
...
@@ -801,11 +808,14 @@ class S3_files extends Files_common implements Files{
// nettoyage en local
// nettoyage en local
@
unlink
(
$sPath
.
".zip"
);
@
unlink
(
$sPath
.
".zip"
);
}
else
{
}
else
{
writeToErrorLog
(
"Can't unzip : "
.
$sZipFile
);
return
false
;
return
false
;
}
}
}
else
{
}
else
{
writeToErrorLog
(
"Can't do a local copy of : "
.
$sZipFile
);
return
false
;
return
false
;
}
}
return
true
;
}
}
/**
/**
*zip a directory and it content.
*zip a directory and it content.
...
@@ -869,6 +879,7 @@ class S3_files extends Files_common implements Files{
...
@@ -869,6 +879,7 @@ class S3_files extends Files_common implements Files{
}
else
{
}
else
{
return
false
;
return
false
;
}
}
return
true
;
}
}
/**
/**
*unzip an archive on s3.
*unzip an archive on s3.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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