Skip to content
Snippets Groups Projects
Commit 0b83dc2d authored by Anthony Borghi's avatar Anthony Borghi
Browse files

Retouche fonctions de gestion d'archive après test

parent 1af34c8f
Branches
Tags
No related merge requests found
...@@ -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
......
...@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment