From 3c6cb85c744655d80c5eeda413ed35f2cb4f7301 Mon Sep 17 00:00:00 2001 From: szaimen Date: Sat, 21 May 2022 21:33:07 +0200 Subject: [PATCH] fix host mounts for windows Signed-off-by: szaimen --- php/src/Data/ConfigurationManager.php | 20 ++++++++++++++++++++ php/src/Docker/DockerActionManager.php | 26 +++++++++++++++++++++++--- readme.md | 2 -- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index fc440af6..9acabc14 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -512,4 +512,24 @@ class ConfigurationManager $config['timezone'] = ''; $this->WriteConfig($config); } + + public function isWindowsPath(string $path) : bool { + $windowsPath = '/host_mnt/'; + if (str_starts_with($path, $windowsPath)) { + return true; + } + return false; + } + + public function GetWindowsVolumeName(string $volumeName) : string { + $name = ''; + if ($volumeName === $this->GetNextcloudDatadirMount()) { + $name = 'nextcloud_aio_nextcloud_data'; + } elseif ($volumeName === $this->GetNextcloudMount()) { + $name = 'nextcloud_aio_nextcloud_mount'; + } elseif ($volumeName === $this->GetBorgBackupHostLocation()) { + $name = 'nextcloud_aio_backup'; + } + return $name; + } } diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index b4f03b44..313d41d3 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -186,13 +186,30 @@ class DockerActionManager ]; $firstChar = substr($volume->name, 0, 1); - if(!in_array($firstChar, $forbiddenChars)) { + if (!in_array($firstChar, $forbiddenChars)) { $this->guzzleClient->request( 'POST', $url, [ 'json' => [ - 'name' => $volume->name, + 'Name' => $volume->name, + ], + ] + ); + } elseif ($this->configurationManager->isWindowsPath($volume->name)) { + $name = $this->configurationManager->GetWindowsVolumeName($volume->name); + $this->guzzleClient->request( + 'POST', + $url, + [ + 'json' => [ + 'Name' => $name, + 'Driver' => 'local', + 'DriverOpts' => [ + 'type' => 'none', + 'device' => $volume->name, + 'o' => 'bind', + ] ], ] ); @@ -203,8 +220,11 @@ class DockerActionManager public function CreateContainer(Container $container) : void { $volumes = []; foreach($container->GetVolumes()->GetVolumes() as $volume) { + if ($this->configurationManager->isWindowsPath($volume->name)) { + $volume->name = $this->configurationManager->GetWindowsVolumeName($volume->name); + } $volumeEntry = $volume->name . ':' . $volume->mountPoint; - if($volume->isWritable) { + if ($volume->isWritable) { $volumeEntry = $volumeEntry . ':' . 'rw'; } else { $volumeEntry = $volumeEntry . ':' . 'ro'; diff --git a/readme.md b/readme.md index c201d641..086cb233 100644 --- a/readme.md +++ b/readme.md @@ -94,8 +94,6 @@ docker run -it ^ nextcloud/all-in-one:latest ``` -**Please note:** AIO works on Windows in general but due to a bug in `Docker for Windows`, it currently does not support mounting directories from the host into AIO which means that `NEXTCLOUD_DATADIR`, `NEXTCLOUD_MOUNT` do not work and the built-in backup solution is not able to write to the host OS. See https://github.com/nextcloud/all-in-one/discussions/600. - ### How to resolve firewall problems with Fedora Linux, RHEL OS, CentOS, SUSE Linux and others?