Recursively lock folder contents

This commit is contained in:
Thomas Müller 2015-10-05 17:31:37 +02:00
parent 3bf818450a
commit 57f841da2c
1 changed files with 27 additions and 6 deletions

View File

@ -40,6 +40,7 @@
*
*/
use OC\Files\View;
use OC\Streamer;
use OCP\Lock\ILockingProvider;
@ -123,14 +124,10 @@ class OC_Files {
$view->lockFile($filename, ILockingProvider::LOCK_SHARED);
}
if ($getType === self::ZIP_FILES) {
foreach ($files as $file) {
$file = $dir . '/' . $file;
$view->lockFile($file, ILockingProvider::LOCK_SHARED);
}
self::lockFiles($view, $dir, $files);
}
if ($getType === self::ZIP_DIR) {
$file = $dir . '/' . $files;
$view->lockFile($file, ILockingProvider::LOCK_SHARED);
self::lockFiles($view, $dir, $files);
}
if ($streamer) {
@ -189,6 +186,30 @@ class OC_Files {
}
}
/**
* @param View $view
* @param $dir
* @param string[]|string $files
*/
public static function lockFiles($view, $dir, $files) {
if (!is_array($files)) {
$file = $dir . '/' . $files;
$files = [$file];
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
$view->lockFile($file, ILockingProvider::LOCK_SHARED);
if ($view->is_dir($file)) {
$contents = $view->getDirectoryContent($file);
$contents = array_map(function($fileInfo) use ($file) {
/** @var \OCP\Files\FileInfo $fileInfo */
return $file . '/' . $fileInfo->getName();
}, $contents);
self::lockFiles($view, $dir, $contents);
}
}
}
/**
* set the maximum upload size limit for apache hosts using .htaccess
*