MDL-58718 filestorage: Normalise file paths for Windows
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 26 Apr 2017 01:35:19 +0000 (09:35 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 26 Apr 2017 01:36:10 +0000 (09:36 +0800)
lib/filestorage/file_system_filedir.php
lib/filestorage/tests/file_storage_test.php
lib/filestorage/tests/file_system_test.php
lib/filestorage/tests/tgz_packer_test.php

index 82f6b5c..816f7d6 100644 (file)
@@ -109,7 +109,7 @@ class file_system_filedir extends file_system {
      * @return string The full path to the content file
      */
     protected function get_local_path_from_hash($contenthash, $fetchifnotfound = false) {
-        return $this->get_fulldir_from_hash($contenthash) . DIRECTORY_SEPARATOR . $contenthash;
+        return $this->get_fulldir_from_hash($contenthash) . '/' .$contenthash;
     }
 
     /**
@@ -171,7 +171,7 @@ class file_system_filedir extends file_system {
      * @return string The full path to the content directory
      */
     protected function get_fulldir_from_hash($contenthash) {
-        return $this->filedir . DIRECTORY_SEPARATOR . $this->get_contentdir_from_hash($contenthash);
+        return $this->filedir . '/' . $this->get_contentdir_from_hash($contenthash);
     }
 
     /**
@@ -198,7 +198,7 @@ class file_system_filedir extends file_system {
      * @return string The filepath within filedir
      */
     protected function get_contentpath_from_hash($contenthash) {
-        return $this->get_contentdir_from_hash($contenthash) . "/$contenthash";
+        return $this->get_contentdir_from_hash($contenthash) . '/' . $contenthash;
     }
 
     /**
@@ -209,7 +209,7 @@ class file_system_filedir extends file_system {
      * @return string The full path to the trash directory
      */
     protected function get_trash_fulldir_from_hash($contenthash) {
-        return $this->trashdir . DIRECTORY_SEPARATOR . $this->get_contentdir_from_hash($contenthash);
+        return $this->trashdir . '/' . $this->get_contentdir_from_hash($contenthash);
     }
 
     /**
@@ -219,7 +219,7 @@ class file_system_filedir extends file_system {
      * @return string The full path to the trash file
      */
     protected function get_trash_fullpath_from_hash($contenthash) {
-        return $this->trashdir . DIRECTORY_SEPARATOR . $this->get_contentpath_from_hash($contenthash);
+        return $this->trashdir . '/' . $this->get_contentpath_from_hash($contenthash);
     }
 
     /**
@@ -251,7 +251,7 @@ class file_system_filedir extends file_system {
         $contenthash = $file->get_contenthash();
         $contentdir = $this->get_fulldir_from_storedfile($file);
         $trashfile = $this->get_trash_fullpath_from_hash($contenthash);
-        $alttrashfile = $this->trashdir . DIRECTORY_SEPARATOR . $contenthash;
+        $alttrashfile = "{$this->trashdir}/{$contenthash}";
 
         if (!is_readable($trashfile)) {
             // The trash file was not found. Check the alternative trash file too just in case.
index 08febf3..fdbece5 100644 (file)
@@ -1867,7 +1867,7 @@ class core_files_file_storage_testcase extends advanced_testcase {
      * errors and behaves as expected.
      */
     public function test_mimetype_known() {
-        $filepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'testimage.jpg';
+        $filepath = __DIR__ . '/fixtures/testimage.jpg';
         $mimetype = file_storage::mimetype_from_file($filepath);
         $this->assertEquals('image/jpeg', $mimetype);
     }
@@ -1890,7 +1890,7 @@ class core_files_file_storage_testcase extends advanced_testcase {
      * errors and behaves as expected.
      */
     public function test_mimetype_from_file_known() {
-        $filepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'testimage.jpg';
+        $filepath = __DIR__ . '/fixtures/testimage.jpg';
         $mimetype = file_storage::mimetype_from_file($filepath);
         $this->assertEquals('image/jpeg', $mimetype);
     }
index 89162f4..adf539f 100644 (file)
@@ -847,7 +847,7 @@ class core_files_file_system_testcase extends advanced_testcase {
      * for an image.
      */
     public function test_get_imageinfo_from_path() {
-        $filepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'testimage.jpg';
+        $filepath = __DIR__ . "/fixtures/testimage.jpg";
 
         // Get the filesystem mock.
         $fs = $this->get_testable_mock();
@@ -906,7 +906,7 @@ class core_files_file_system_testcase extends advanced_testcase {
 
         $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
         $fs->method('get_remote_path_from_storedfile')
-            ->willReturn(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'test.tgz');
+            ->willReturn(__DIR__ . "/fixtures/test.tgz");
 
         // Note: We are unable to determine the mode in which the $fh was opened.
         $fh = $fs->get_content_file_handle($file, stored_file::FILE_HANDLE_GZOPEN);
@@ -956,7 +956,7 @@ class core_files_file_system_testcase extends advanced_testcase {
         $contenthash = file_storage::hash_from_string($filecontent);
         $filename = 'example';
 
-        $filepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'testimage.jpg';
+        $filepath = __DIR__ . "/fixtures/testimage.jpg";
         $fs = $this->get_testable_mock(['get_remote_path_from_hash']);
         $fs->method('get_remote_path_from_hash')->willReturn($filepath);
 
@@ -974,7 +974,7 @@ class core_files_file_system_testcase extends advanced_testcase {
         $contenthash = file_storage::hash_from_string($filecontent);
         $filename = 'example';
 
-        $filepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'testimage.jpg';
+        $filepath = __DIR__ . "/fixtures/testimage.jpg";
 
         $fs = $this->get_testable_mock([
             'get_remote_path_from_hash',
@@ -1022,7 +1022,7 @@ class core_files_file_system_testcase extends advanced_testcase {
      * a locally available file whose filename does not suggest mimetype.
      */
     public function test_mimetype_from_storedfile_using_file_content() {
-        $filepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'testimage.jpg';
+        $filepath = __DIR__ . "/fixtures/testimage.jpg";
         $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']);
         $fs->method('get_remote_path_from_storedfile')->willReturn($filepath);
 
@@ -1037,7 +1037,7 @@ class core_files_file_system_testcase extends advanced_testcase {
      * a remotely available file whose filename does not suggest mimetype.
      */
     public function test_mimetype_from_storedfile_using_file_content_remote() {
-        $filepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'testimage.jpg';
+        $filepath = __DIR__ . "/fixtures/testimage.jpg";
 
         $fs = $this->get_testable_mock([
             'get_remote_path_from_storedfile',
index 3d66b75..f12668e 100644 (file)
@@ -255,7 +255,7 @@ class core_files_tgz_packer_testcase extends advanced_testcase implements file_p
 
         // Prepare files.
         $files = $this->prepare_file_list();
-        $archivefile = make_request_directory() . DIRECTORY_SEPARATOR . 'test.tgz';
+        $archivefile = make_request_directory() . '/test.tgz';
         $packer->archive_to_pathname($files, $archivefile);
 
         // Extract same files.
@@ -272,7 +272,7 @@ class core_files_tgz_packer_testcase extends advanced_testcase implements file_p
         $packer = get_file_packer('application/x-gzip');
 
         // Create sample files.
-        $archivefile = make_request_directory() . DIRECTORY_SEPARATOR . 'test.tgz';
+        $archivefile = make_request_directory() . '/test.tgz';
         file_put_contents($archivefile, '');
 
         // Extract same files.