diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-05 17:31:37 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-05 17:31:37 +0200 |
commit | 57f841da2c414209ad9d4ae5a1cd0ac5ba604b7b (patch) | |
tree | 0477b804ae8f55213dec1d1921c5703425de8389 /lib/private/files.php | |
parent | 3bf818450a826d296b8e56ab41f91b3f9f8112f1 (diff) | |
download | nextcloud-server-57f841da2c414209ad9d4ae5a1cd0ac5ba604b7b.tar.gz nextcloud-server-57f841da2c414209ad9d4ae5a1cd0ac5ba604b7b.zip |
Recursively lock folder contents
Diffstat (limited to 'lib/private/files.php')
-rw-r--r-- | lib/private/files.php | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/private/files.php b/lib/private/files.php index af3a8ac574d..099602d56b0 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -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) { @@ -190,6 +187,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 * * @param int $size file size in bytes |