Example #1
0
/**
 * Unlinks all subdirectories and files in $dir
 * Works only on one subdir level, will not recurse
 */
function oos_unlink_temp_dir($dir)
{
    $h1 = opendir($dir);
    while ($subdir = readdir($h1)) {
        // Ignore non directories
        if (!is_dir($dir . $subdir)) {
            continue;
        }
        // Ignore . and .. and CVS
        if ($subdir == '.' || $subdir == '..' || $subdir == 'CVS' || $subdir == '.svn') {
            continue;
        }
        // Loop and unlink files in subdirectory
        $h2 = opendir($dir . $subdir);
        while ($file = readdir($h2)) {
            if ($file == '.' || $file == '..') {
                continue;
            }
            @unlink($dir . $subdir . '/' . $file);
        }
        closedir($h2);
        @rmdir($dir . $subdir);
    }
    closedir($h1);
}
Example #2
0
/**
 * Recursively delete an entire directory.
 *
 * @since 4.6
 * @package all
 * @param string $directory The dir you want to remove.
 * @param bool $empty Should the dir remain empty?
 * @return bool
 */
function recursive_remove_directory($directory, $empty = false)
{
    if (substr($directory, -1) == '/') {
        $directory = substr($directory, 0, -1);
    }
    if (!file_exists($directory) || !is_dir($directory)) {
        return false;
    } elseif (is_readable($directory)) {
        $handle = opendir($directory);
        while (false !== ($item = readdir($handle))) {
            if ($item != '.' && $item != '..') {
                $path = $directory . '/' . $item;
                if (is_dir($path)) {
                    recursive_remove_directory($path);
                } else {
                    unlink($path);
                }
            }
        }
        closedir($handle);
        if (!$empty) {
            if (!rmdir($directory)) {
                return false;
            }
        }
    }
    return true;
}
Example #3
0
 public function rmdir()
 {
     $tmpDir = $this->getTmpDir(false);
     foreach (glob("{$tmpDir}*") as $dirname) {
         @rmdir($dirname);
     }
 }
function w_rmdir_recursive_inner($path)
{
    # avoid opening a handle on the dir in case that impacts
    # delete latency on windows
    if (@rmdir($path) || @unlink($path)) {
        return true;
    }
    clearstatcache();
    if (is_dir($path)) {
        # most likely failure reason is that the dir is not empty
        $kids = @scandir($path);
        if (is_array($kids)) {
            foreach ($kids as $kid) {
                if ($kid == '.' || $kid == '..') {
                    continue;
                }
                w_rmdir_recursive($path . DIRECTORY_SEPARATOR . $kid);
            }
        }
        if (is_dir($path)) {
            return @rmdir($path);
        }
    }
    if (is_file($path)) {
        return unlink($path);
    }
    return !file_exists($path);
}
Example #5
0
 function recursiveRemDir($directory, $empty = FALSE)
 {
     if (substr($directory, -1) == '/') {
         $directory = substr($directory, 0, -1);
     }
     if (!file_exists($directory) || !is_dir($directory)) {
         return FALSE;
     } elseif (is_readable($directory)) {
         $handle = opendir($directory);
         while (FALSE !== ($item = readdir($handle))) {
             if ($item != '.' && $item != '..') {
                 $path = $directory . '/' . $item;
                 if (is_dir($path)) {
                     Y::recursiveRemDir($path);
                 } else {
                     unlink($path);
                 }
             }
         }
         closedir($handle);
         if ($empty == FALSE) {
             if (!rmdir($directory)) {
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
Example #6
0
/**
 * Tries to delete the directory recursivaly.
 * @return true on success.
 */
function osc_deleteDir($path)
{
    if (!is_dir($path)) {
        return false;
    }
    $fd = @opendir($path);
    if (!$fd) {
        return false;
    }
    while ($file = @readdir($fd)) {
        if ($file != '.' && $file != '..') {
            if (!is_dir($path . '/' . $file)) {
                if (!@unlink($path . '/' . $file)) {
                    closedir($fd);
                    return false;
                } else {
                    osc_deleteDir($path . '/' . $file);
                }
            } else {
                osc_deleteDir($path . '/' . $file);
            }
        }
    }
    closedir($fd);
    return @rmdir($path);
}
Example #7
0
 /**
  * Destroys the test directory.
  */
 protected function tearDown()
 {
     unlink($this->path . '/a');
     unlink($this->path . '/sub/b');
     rmdir($this->path . '/sub');
     rmdir($this->path);
 }
 /**
  * Clear all files in a given directory.
  *
  * @param  string An absolute filesystem path to a directory.
  *
  * @return void
  */
 public static function clearDirectory($directory)
 {
     if (!is_dir($directory)) {
         return;
     }
     // open a file point to the cache dir
     $fp = opendir($directory);
     // ignore names
     $ignore = array('.', '..', 'CVS', '.svn');
     while (($file = readdir($fp)) !== false) {
         if (!in_array($file, $ignore)) {
             if (is_link($directory . '/' . $file)) {
                 // delete symlink
                 unlink($directory . '/' . $file);
             } else {
                 if (is_dir($directory . '/' . $file)) {
                     // recurse through directory
                     self::clearDirectory($directory . '/' . $file);
                     // delete the directory
                     rmdir($directory . '/' . $file);
                 } else {
                     // delete the file
                     unlink($directory . '/' . $file);
                 }
             }
         }
     }
     // close file pointer
     closedir($fp);
 }
 public function filterLoad(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->emberBin) : array($this->emberBin));
     $templateName = basename($asset->getSourcePath());
     $inputDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('input_dir');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName;
     $outputPath = tempnam(sys_get_temp_dir(), 'output');
     mkdir($inputDirPath);
     file_put_contents($inputPath, $asset->getContent());
     $pb->add($inputPath)->add('-f')->add($outputPath);
     if ($this->includeBaseDir) {
         $pb->add('-b')->add($inputDirPath . DIRECTORY_SEPARATOR);
     }
     $process = $pb->getProcess();
     $returnCode = $process->run();
     unlink($inputPath);
     rmdir($inputDirPath);
     if (127 === $returnCode) {
         throw new \RuntimeException('Path to node executable could not be resolved.');
     }
     if (0 !== $returnCode) {
         if (file_exists($outputPath)) {
             unlink($outputPath);
         }
         throw FilterException::fromProcess($process)->setInput($asset->getContent());
     }
     if (!file_exists($outputPath)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $compiledJs = file_get_contents($outputPath);
     unlink($outputPath);
     $asset->setContent($compiledJs);
 }
 protected function removeDirs($dirs)
 {
     $appPath = $this->app['path'];
     foreach ($dirs as $dir) {
         is_dir($appPath . '/' . $dir) and rmdir($appPath . '/' . $dir);
     }
 }
Example #11
0
 /**
  * Delete a folder (and all files and folders below it)
  * @param string $path Path to folder to be deleted
  * @param bool $deleteSelf true if the folder should be deleted. false if just its contents.
  * @return int|bool Returns the total of deleted files/folder. Returns false if delete failed
  */
 public function delete($path, $deleteSelf = true)
 {
     if (file_exists($path)) {
         //delete all sub folder/files under, then delete the folder itself
         if (is_dir($path)) {
             if ($path[strlen($path) - 1] != '/' && $path[strlen($path) - 1] != '\\') {
                 $path .= DIRECTORY_SEPARATOR;
                 $path = str_replace('\\', '/', $path);
             }
             if ($total = $this->purgeContent($path)) {
                 if ($deleteSelf) {
                     if ($t = rmdir($path)) {
                         return $total + $t;
                     }
                 }
                 return $total;
             } else {
                 if ($deleteSelf) {
                     return rmdir($path);
                 }
             }
             return false;
         } else {
             return unlink($path);
         }
     }
 }
Example #12
0
 /**
  * Tears down the fixture, for example, close a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     if (file_exists($this->zf2rapidValidatorDir . $this->zf2rapidValidatorFile)) {
         unlink($this->zf2rapidValidatorDir . $this->zf2rapidValidatorFile);
     }
     rmdir($this->zf2rapidValidatorDir);
 }
Example #13
0
 public function saveRenditions($renditions, $dir)
 {
     if ($dir[strlen($dir) - 1] !== '/') {
         $dir .= '/';
     }
     $retval = array();
     $tmpdir = '';
     foreach ($renditions as $name => $file) {
         $remote_file = $dir . basename($file);
         $this->save($file, $remote_file);
         $retval[$name] = $remote_file;
         // Remove the temporary file
         if (file_exists($file)) {
             unlink($file);
         } else {
             $log = new api_log();
             $log->warn("storage_driver_s3::saveRenditions() - No temp file for rendition '%s' at '%s'", $name, $file);
         }
         if (empty($tmpdir)) {
             $tmpdir = dirname($file);
         }
     }
     if ($tmpdir !== '') {
         // Optimistic removal. If it's not empty, this will fail.
         @rmdir($tmpdir);
         if (file_exists($tmpdir)) {
             $log = new api_log();
             $log->warn("storage_driver_s3::saveRenditions() - unable to remove rendition tmpdir '%s'", $tmpdir);
         }
     }
     return $retval;
 }
Example #14
0
function full_rmdir($dir)
{
    if (!is_writable($dir)) {
        if (!@chmod($dir, WT_PERM_EXE)) {
            return false;
        }
    }
    $d = dir($dir);
    while (false !== ($entry = $d->read())) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        $entry = $dir . '/' . $entry;
        if (is_dir($entry)) {
            if (!full_rmdir($entry)) {
                return false;
            }
            continue;
        }
        if (!@unlink($entry)) {
            $d->close();
            return false;
        }
    }
    $d->close();
    rmdir($dir);
    return TRUE;
}
Example #15
0
/**
 * Рекурсивно удаляет директорию
 * @param string $directory
 * @param bool $is_clear Если TRUE, то директория будет очищена, но не удалена
 * @return bool
 */
function files_remove_directory($directory, $is_clear = false)
{
    if (substr($directory, -1) == '/') {
        $directory = substr($directory, 0, -1);
    }
    if (!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
        return false;
    }
    $handle = opendir($directory);
    while (false !== ($node = readdir($handle))) {
        if ($node != '.' && $node != '..') {
            $path = $directory . '/' . $node;
            if (is_dir($path)) {
                if (!files_remove_directory($path)) {
                    return false;
                }
            } else {
                if (!@unlink($path)) {
                    return false;
                }
            }
        }
    }
    closedir($handle);
    if ($is_clear == false) {
        if (!@rmdir($directory)) {
            return false;
        }
    }
    return true;
}
Example #16
0
function generateDocs($folder = 'creamture')
{
    if (!file_exists('docs/' . $folder)) {
        println('Docs folder doesn\'t exists');
        return;
    }
    $daux_global = array('docs_directory' => '../../../docs/' . $folder, 'valid_markdown_extensions' => array('md', 'markdown'));
    if (file_put_contents('docs/global.json', json_encode($daux_global)) === FALSE) {
        println('Error writing global conf in docs folder');
        exit;
    }
    require_once 'vendor/justinwalsh/daux.io/libs/daux.php';
    foreach (glob('docs/assets/templates/*') as $directory) {
        if (strpos('.', $directory) < 0) {
            @rmdir('vendor/justinwalsh/daux.io/templates/' . $directory);
        }
    }
    //Copy alternative imgs, js and templates
    directory_copy('docs/assets/templates', 'vendor/justinwalsh/daux.io/templates');
    if (file_exists('docs/assets/' . $folder . '_img')) {
        directory_copy('docs/assets/' . $folder . '_img', 'vendor/justinwalsh/daux.io/img');
    }
    $Daux = new \Todaymade\Daux\Daux(realpath('docs/global.json'));
    $Daux->initialize();
    if (!file_exists(PUBLICPATH . 'docs/' . $folder)) {
        mkdir(PUBLICPATH . 'docs/' . $folder, 0777, TRUE);
    }
    $Daux->generate_static(PUBLICPATH . 'docs/' . $folder);
    println('Docs generated in public folder');
}
Example #17
0
function smarty_core_rmdir($params, &$smarty)
{
    if (!isset($params['level'])) {
        $params['level'] = 1;
    }
    if (!isset($params['exp_time'])) {
        $params['exp_time'] = null;
    }
    if ($_handle = opendir($params['dirname'])) {
        while (false !== ($_entry = readdir($_handle))) {
            if ($_entry != '.' && $_entry != '..') {
                if (is_dir($params['dirname'] . DIRECTORY_SEPARATOR . $_entry)) {
                    $_params = array('dirname' => $params['dirname'] . DIRECTORY_SEPARATOR . $_entry, 'level' => $params['level'] + 1, 'exp_time' => $params['exp_time']);
                    smarty_core_rmdir($_params, $smarty);
                } else {
                    $smarty->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']);
                }
            }
        }
        closedir($_handle);
    }
    if ($params['level']) {
        return rmdir($params['dirname']);
    }
    return (bool) $_handle;
}
Example #18
0
function rmdir_r($path)
{
    if (!is_dir($path)) {
        return false;
    }
    $stack = array($path);
    while ($dir = array_pop($stack)) {
        if (@rmdir($dir)) {
            continue;
        }
        $stack[] = $dir;
        $dh = opendir($dir);
        while (($child = readdir($dh)) !== false) {
            if ($child[0] == '.') {
                continue;
            }
            $child = $dir . DIRECTORY_SEPARATOR . $child;
            if (is_dir($child)) {
                $stack[] = $child;
            } else {
                unlink($child);
            }
        }
    }
    return true;
}
Example #19
0
 public function filterLoad(AssetInterface $asset)
 {
     $builder = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->jsxBin) : array($this->jsxBin));
     $inputDir = FilesystemUtils::createThrowAwayDirectory('jsx_in');
     $inputFile = $inputDir . DIRECTORY_SEPARATOR . 'asset.js';
     $outputDir = FilesystemUtils::createThrowAwayDirectory('jsx_out');
     $outputFile = $outputDir . DIRECTORY_SEPARATOR . 'asset.js';
     // create the asset file
     file_put_contents($inputFile, $asset->getContent());
     $builder->add($inputDir)->add($outputDir)->add('--no-cache-dir');
     $proc = $builder->getProcess();
     $code = $proc->run();
     // remove the input directory and asset file
     unlink($inputFile);
     rmdir($inputDir);
     if (0 !== $code) {
         if (file_exists($outputFile)) {
             unlink($outputFile);
         }
         if (file_exists($outputDir)) {
             rmdir($outputDir);
         }
         throw FilterException::fromProcess($proc);
     }
     $asset->setContent(file_get_contents($outputFile));
     // remove the output directory and processed asset file
     unlink($outputFile);
     rmdir($outputDir);
 }
Example #20
0
 /**
  * ディレクトリごと再帰的に削除
  *
  * 中にファイルが入っていても削除する。
  *
  * @param string $dir ディレクトリ名
  * @param bool $remove_top トップのディレクトリを削除するか
  * @param string $hook_func 削除ごとに実行する関数を指定。
  */
 public static function removeDir($dir, $remove_top = true, $hook_func = '')
 {
     if (is_file($dir)) {
         unlink($dir);
         if ($hook_func) {
             call_user_func($hook_func, 'delete_file', $dir);
         }
     } else {
         if (is_dir($dir)) {
             if (ECF_FILE_FILESYSTEMITERATOR_EXIST) {
                 $iterator = new RecursiveDirectoryiterator($dir, FilesystemIterator::SKIP_DOTS);
             } else {
                 $iterator = new RecursiveDirectoryiterator($dir);
             }
             foreach ($iterator as $path) {
                 if ($path->isDir()) {
                     File::removeDir($path->getPathname());
                 } else {
                     unlink($path->getPathname());
                 }
             }
             if ($remove_top) {
                 rmdir($dir);
                 if ($hook_func) {
                     call_user_func($hook_func, 'delete_dir', $dir);
                 }
             }
         }
     }
     if (file_exists($dir)) {
         return false;
     } else {
         return true;
     }
 }
Example #21
0
/**
 * 删除非空目录(v2.0.12后版本弃用)
 *
 * @param	string	$dir	目录名称
 * @return	bool|void
 */
function dr_rmdir($dir)
{
    if (!$dir || is_file(trim($dir, DIRECTORY_SEPARATOR) . '/index.php')) {
        return FALSE;
    }
    @rmdir($dir);
}
 /**
  * Tears down the fixture, for example, close a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     if (file_exists($this->zf2rapidControllerPluginDir . $this->zf2rapidControllerPluginFile)) {
         unlink($this->zf2rapidControllerPluginDir . $this->zf2rapidControllerPluginFile);
     }
     rmdir($this->zf2rapidControllerPluginDir);
 }
Example #23
0
 /**
  * if the parent of the mount point is gone then the mount point should move up
  *
  * @medium
  */
 function testParentOfMountPointIsGone()
 {
     // share to user
     $fileinfo = $this->view->getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $this->assertTrue($user2View->file_exists($this->folder));
     // create a local folder
     $result = $user2View->mkdir('localfolder');
     $this->assertTrue($result);
     // move mount point to local folder
     $result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
     $this->assertTrue($result);
     // mount point in the root folder should no longer exist
     $this->assertFalse($user2View->is_dir($this->folder));
     // delete the local folder
     $fullPath = \OC_Config::getValue('datadirectory') . '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder';
     rmdir($fullPath);
     //enforce reload of the mount points
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     //mount point should be back at the root
     $this->assertTrue($user2View->is_dir($this->folder));
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->view->unlink($this->folder);
 }
Example #24
0
 private static function unlinkDirectory($path)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
     $iterator->rewind();
     $files = array();
     $directories = array();
     foreach ($iterator as $path => $directory) {
         if (is_file($path)) {
             $files[] = $path;
         } elseif (is_dir($path)) {
             $directories[] = $path;
         }
     }
     // Remove the files, then the directories
     foreach ($files as $filePath) {
         self::unlinkFile($filePath);
     }
     foreach ($directories as $dirPath) {
         rmdir($dirPath);
     }
     // Finally, remove the path itself
     if (is_dir($path)) {
         rmdir($path);
     }
 }
function sup_repertoire($chemin)
{
    // vérifie si le nom du repertoire contient "/" à la fin
    if ($chemin[strlen($chemin) - 1] != '/') {
        $chemin .= '/';
        // rajoute '/'
    }
    if (is_dir($chemin)) {
        $sq = opendir($chemin);
        // lecture
        while ($f = readdir($sq)) {
            if ($f != '.' && $f != '..') {
                $fichier = $chemin . $f;
                // chemin fichier
                if (is_dir($fichier)) {
                    sup_repertoire($fichier);
                    // rapel la fonction de manière récursive
                } else {
                    unlink($fichier);
                    // sup le fichier
                }
            }
        }
        closedir($sq);
        rmdir($chemin);
        // sup le répertoire
    } else {
        unlink($chemin);
        // sup le fichier
    }
}
Example #26
0
function registerUser($userName, $userMail, $userPasswd, $salt)
{
    $fileMail = fopen("database/email", "a+");
    if ($fileMail) {
        mkdir("database/users/{$userName}", 0755);
        mkdir("database/users/{$userName}/tasks", 0755);
        $fileName = fopen("database/users/{$userName}/{$userName}.usr", "a+");
        if ($fileName) {
            $filePasswd = fopen("database/passwd", "a+");
            if ($filePasswd) {
                /* creating user file in database */
                /* registering e-mail adress in database */
                fprintf($fileMail, "{$userMail}\n");
                fprintf($fileName, "{$userName}:{$userMail}\n");
                /* registering user's password in database */
                $PasswdCrypt = sha1(sha1("{$userPasswd}") . $salt);
                fprintf($filePasswd, "{$userName}:{$PasswdCrypt}\n");
                fclose($fileName);
            } else {
                rmdir("database/users/{$userName}");
                rmdir("database/users/{$userName}/tasks");
            }
            fclose($fileMail);
        } else {
            rmdir("database/users/{$userName}");
            rmdir("database/users/{$userName}/tasks");
        }
        fclose($filePasswd);
    }
}
 public static function clearCache()
 {
     if (!is_dir(CACHE_PATH)) {
         return;
     }
     try {
         $dirIterator = new RecursiveDirectoryIterator(CACHE_PATH);
         $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($iterator as $path) {
             switch (true) {
                 case '.' == basename($path->__toString()):
                 case '..' == basename($path->__toString()):
                 case '...' == basename($path->__toString()):
                     break;
                 case $path->isDir():
                     rmdir($path->__toString());
                     break;
                 default:
                     unlink($path->__toString());
                     break;
             }
         }
         rmdir(CACHE_PATH);
     } catch (Exception $e) {
         throw $e;
     }
 }
 function delDir($dirName, $orig = false)
 {
     if (!$orig) {
         $orig = $dirName;
     }
     if (empty($dirName)) {
         return true;
     }
     if (file_exists($dirName)) {
         $dir = dir($dirName);
         while ($file = $dir->read()) {
             if ($file != '.' && $file != '..') {
                 if (is_dir($dirName . '/' . $file)) {
                     Pommo_Helper_Maintenance::delDir($dirName . '/' . $file, $orig);
                 } else {
                     unlink($dirName . '/' . $file) or die('File ' . $dirName . '/' . $file . ' couldn\'t be deleted!');
                 }
             }
         }
         $dir->close();
         if ($dirName != $orig) {
             @rmdir($dirName) or die('Folder ' . $dirName . ' couldn\'t be deleted!');
         }
     } else {
         return false;
     }
     return true;
 }
Example #29
0
 protected function rmDir($dir)
 {
     if (is_dir($dir)) {
         chmod($dir, 0777);
         rmdir($dir);
     }
 }
 protected function tearDown()
 {
     if (is_file(__DIR__ . '/log/test.log')) {
         unlink(__DIR__ . '/log/test.log');
     }
     rmdir(__DIR__ . '/log');
 }