Make sure the path can be written to.
[core.git] / inc / classes / main / file_directories / io / class_FrameworkFileInputOutputPointer.php
index edf9f5728a4dae33058261bed2f3af15fbd3e56d..ae372f3532b56aeb6321b892855dca0c96edfd6b 100644 (file)
@@ -41,6 +41,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         * @throws      FileIsEmptyException            If the given file name is NULL or empty
         * @throws      FileReadProtectedException      If PHP cannot read an existing file
         * @throws      FileWriteProtectedException     If PHP cannot write an existing file
+        * @throws      PathWriteProtectedException     If PHP cannot write to an existing path
         * @throws      FileIoException                         If fopen() returns not a file resource
         */
        public static final function createFrameworkFileInputOutputPointer ($fileName) {
@@ -51,12 +52,15 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                } elseif (!BaseFrameworkSystem::isReachableFilePath($fileName)) {
                        // File exists but cannot be read
                        throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
-               } elseif (!BaseFrameworkSystem::isReadableFile($fileName)) {
+               } elseif ((!BaseFrameworkSystem::isReadableFile($fileName)) && (file_exists($fileName))) {
                        // File exists but cannot be read
                        throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
-               } elseif (!is_writable($fileName)) {
+               } elseif ((file_exists($fileName)) && (!is_writable($fileName))) {
                        // File exists but cannot be written
                        throw new FileWriteProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_WRITTEN);
+               } elseif (!is_writable(dirname($fileName))) {
+                       // Path is not writable
+                       throw new PathWriteProtectedException($fileName, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
                }
 
                // Try to open a handler