From 5585f89e9a7607cf0d92c70337c8286e16fc0523 Mon Sep 17 00:00:00 2001 From: Don Richards <2738244+DonRichards@users.noreply.github.com> Date: Thu, 16 Feb 2023 09:56:33 -0500 Subject: [PATCH] Update MediaSourceService.php --- src/MediaSource/MediaSourceService.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/MediaSource/MediaSourceService.php b/src/MediaSource/MediaSourceService.php index 533789857..5e90e140a 100644 --- a/src/MediaSource/MediaSourceService.php +++ b/src/MediaSource/MediaSourceService.php @@ -289,8 +289,18 @@ public function putToNode( } $directory = $this->fileSystem->dirname($content_location); + + // Check if the directory is writable. + if (!is_writable(dirname($directory))) { + $parent_directory = dirname($directory); + $error_current_user = shell_exec('whoami'); + $sanitized_current_user = str_replace(array("\n", "\r"), '', $error_current_user); + throw new HttpException(500, "The user '$sanitized_current_user' does not have permissions to write to: '$parent_directory' . Error"); + } + + if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { - throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable"); + throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable: $directory"); } // Copy over the file content.