From 1d71a16fdc2f7d1a0cb02a36c1d285007cc841ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Carretero?=
 <frederic.carretero@veremes.com>
Date: Mon, 10 Dec 2018 15:06:58 +0100
Subject: [PATCH] Corrections dans la classe "S3_files"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Des slashs étaient en trop au début de la clé pour le bucket
---
 .../rest/class/vmlib/files/S3_files.class.inc | 42 ++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc b/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc
index 76fee87b..ead65c2a 100644
--- a/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc
+++ b/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc
@@ -51,6 +51,9 @@ class S3_files implements Files{
     public function getFileEtag($sFilePath){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         try {
             $oResult = $this->oS3Client->headObject(array(
@@ -73,6 +76,9 @@ class S3_files implements Files{
 
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         try {
             $this->oS3Client->headObject(array(
@@ -96,6 +102,9 @@ class S3_files implements Files{
     public function file_put_contents ($sFilePath, $sData, $iFlags = 0, $mContext = null){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         try {
             $this->oS3Client->putObject(array(
@@ -123,6 +132,9 @@ class S3_files implements Files{
 
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         $sPath = $this->oProperties['extract_dir'] . "/" . getUniqRandomId();
 
@@ -161,6 +173,9 @@ class S3_files implements Files{
     public function file_get_contents_with_etag ($sFilePath, $sEtag ,$bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         $sPath = $this->oProperties['extract_dir'] . "/" . getUniqRandomId();
 
@@ -196,7 +211,12 @@ class S3_files implements Files{
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sDestFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sDestFilePath);
         $sSourceFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sSourceFilePath);
-
+        // Suppression du slash de début de ligne.
+        if (strpos($sDestFilePath, '/') === 0)
+            $sDestFilePath = substr($sDestFilePath, 1);
+        if (strpos($sSourceFilePath, '/') === 0)
+            $sSourceFilePath = substr($sSourceFilePath, 1);
+        //
         try{
             $this->oS3Client->copyObject(array(
               'Bucket' => $sBucket,
@@ -219,6 +239,11 @@ class S3_files implements Files{
     public function copyInAnotherBucket ($sSourceFilePath, $sDests3Key, $sDestBucket){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sSourceFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sSourceFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sSourceFilePath, '/') === 0)
+            $sSourceFilePath = substr($sSourceFilePath, 1);
+        if (strpos($sDests3Key, '/') === 0)
+            $sDests3Key = substr($sDests3Key, 1);
 
         try{
             $this->oS3Client->copyObject(array(
@@ -241,6 +266,9 @@ class S3_files implements Files{
     public function copyLocalToS3 ($sSourceFilePath, $sDestFilePath){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sDestFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sDestFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sDestFilePath, '/') === 0)
+            $sDestFilePath = substr($sDestFilePath, 1);
 
         try {
             $this->oS3Client->putObject(array(
@@ -263,6 +291,9 @@ class S3_files implements Files{
     public function filesize ($sFilePath){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         try {
             $oResult = $this->oS3Client->headObject(array(
@@ -286,6 +317,9 @@ class S3_files implements Files{
     public function readfile ($sFilePath, $bUseIncludePath = FALSE, $mContext = null){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         $sPath = $this->oProperties['extract_dir'] . "/" . getUniqRandomId();
 
@@ -327,6 +361,9 @@ class S3_files implements Files{
     public function unlink ($sFilePath, $mContext = null){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         try{
             $this->oS3Client->deleteObject(array(
@@ -347,6 +384,9 @@ class S3_files implements Files{
     public function filemtime ($sFilePath){
         list($sBucket, $sPrefix) = $this->getBucketConst();
         $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath);
+        // Suppression du slash de début de ligne.
+        if (strpos($sFilePath, '/') === 0)
+            $sFilePath = substr($sFilePath, 1);
 
         try {
             $oResult = $this->oS3Client->headObject(array(
-- 
GitLab