From 028a9513d522731e05ec2e8221e82a6a36efef04 Mon Sep 17 00:00:00 2001 From: James Fantin-Hardesty <24646452+jfantinhardesty@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:25:47 -0600 Subject: [PATCH 1/3] Use subdirectory to mount with server name --- src/lib/cloudfuse/child_process_linux.cpp | 91 ++++++++++--------- src/lib/cloudfuse/child_process_windows.cpp | 97 ++++++++++++--------- 2 files changed, 105 insertions(+), 83 deletions(-) diff --git a/src/lib/cloudfuse/child_process_linux.cpp b/src/lib/cloudfuse/child_process_linux.cpp index 510f964..cf4f8df 100644 --- a/src/lib/cloudfuse/child_process_linux.cpp +++ b/src/lib/cloudfuse/child_process_linux.cpp @@ -26,45 +26,60 @@ #include "child_process.h" #include #include +#include #include #include -std::string config_template = R"( -allow-other: true -logging: - level: log_err - type: syslog - -components: - - libfuse - - file_cache - - attr_cache - - s3storage - -libfuse: - attribute-expiration-sec: 1800 - entry-expiration-sec: 1800 - negative-entry-expiration-sec: 1800 - ignore-open-flags: true - network-share: true - -file_cache: - path: { 0 } - timeout-sec: 180 - allow-non-empty-temp: true - cleanup-on-start: false - -attr_cache: - timeout-sec: 3600 - -s3storage: - bucket-name: { BUCKET_NAME } - endpoint: { ENDPOINT } - region: { AWS_REGION } -)"; +std::string getSystemName() +{ + std::string systemName; + struct utsname buffer; + if (uname(&buffer) != -1) + { + systemName = buffer.nodename; + } + + return systemName; +} CloudfuseMngr::CloudfuseMngr() { + std::string systemName = getSystemName(); + std::string config_template = R"( + allow-other: true + logging: + level: log_err + type: syslog + + components: + - libfuse + - file_cache + - attr_cache + - s3storage + + libfuse: + attribute-expiration-sec: 1800 + entry-expiration-sec: 1800 + negative-entry-expiration-sec: 1800 + ignore-open-flags: true + network-share: true + + file_cache: + path: { 0 } + timeout-sec: 180 + allow-non-empty-temp: true + cleanup-on-start: false + + attr_cache: + timeout-sec: 3600 + + s3storage: + bucket-name: { BUCKET_NAME } + endpoint: { ENDPOINT } + region: { AWS_REGION } + subdirectory: )" + systemName + + "\n"; + std::string homeEnv; const char *home = std::getenv("HOME"); if (home == nullptr) @@ -80,13 +95,9 @@ CloudfuseMngr::CloudfuseMngr() configFile = homeEnv + "/nx_plugin_config.aes"; templateFile = homeEnv + "/nx_plugin_config.yaml"; - std::ifstream in(templateFile); - if (!in.good()) - { - std::ofstream out(templateFile); - out << config_template; - out.close(); - } + std::ofstream out(templateFile, std::ios::trunc); + out << config_template; + out.close(); } processReturn CloudfuseMngr::spawnProcess(char *const argv[], char *const envp[]) diff --git a/src/lib/cloudfuse/child_process_windows.cpp b/src/lib/cloudfuse/child_process_windows.cpp index 258f3ec..d4ff95e 100644 --- a/src/lib/cloudfuse/child_process_windows.cpp +++ b/src/lib/cloudfuse/child_process_windows.cpp @@ -41,42 +41,6 @@ namespace fs = std::filesystem; #include #include -std::string config_template = R"( -allow-other: true -logging: - level: log_err - type: syslog - -components: - - libfuse - - file_cache - - attr_cache - - s3storage - -libfuse: - attribute-expiration-sec: 1800 - entry-expiration-sec: 1800 - negative-entry-expiration-sec: 1800 - ignore-open-flags: true - network-share: true - -file_cache: - path: { 0 } - timeout-sec: 180 - allow-non-empty-temp: true - cleanup-on-start: false - -attr_cache: - timeout-sec: 3600 - -s3storage: - key-id: { AWS_ACCESS_KEY_ID } - secret-key: { AWS_SECRET_ACCESS_KEY } - bucket-name: { BUCKET_NAME } - endpoint: { ENDPOINT } - region: { AWS_REGION } -)"; - // Return available drive letter to mount std::string getAvailableDriveLetter() { @@ -91,8 +55,59 @@ std::string getAvailableDriveLetter() return "Z:"; } +std::string getSystemName() +{ + std::string systemName; + char computerName[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD size = sizeof(computerName) / sizeof(char); + if (GetComputerName(computerName, &size)) + { + systemName = computerName; + } + + return systemName; +} + CloudfuseMngr::CloudfuseMngr() { + std::string systemName = getSystemName(); + std::string config_template = R"( + allow-other: true + logging: + level: log_err + type: syslog + + components: + - libfuse + - file_cache + - attr_cache + - s3storage + + libfuse: + attribute-expiration-sec: 1800 + entry-expiration-sec: 1800 + negative-entry-expiration-sec: 1800 + ignore-open-flags: true + network-share: true + + file_cache: + path: { 0 } + timeout-sec: 180 + allow-non-empty-temp: true + cleanup-on-start: false + + attr_cache: + timeout-sec: 3600 + + s3storage: + key-id: { AWS_ACCESS_KEY_ID } + secret-key: { AWS_SECRET_ACCESS_KEY } + bucket-name: { BUCKET_NAME } + endpoint: { ENDPOINT } + region: { AWS_REGION } + subdirectory: )" + systemName + + "\n"; + std::string appdataEnv; char *buf = nullptr; size_t len; @@ -116,13 +131,9 @@ CloudfuseMngr::CloudfuseMngr() configFile = configFilePath.generic_string(); templateFile = templateFilePath.generic_string(); - std::ifstream in(templateFile.c_str()); - if (!in.good()) - { - std::ofstream out(templateFile.c_str()); - out << config_template; - out.close(); - } + std::ofstream out(templateFile, std::ios::trunc); + out << config_template; + out.close(); } processReturn CloudfuseMngr::spawnProcess(wchar_t *argv, std::wstring envp) From 5d07d67d9af90d5e290c97a5840bdc3f3e493ef3 Mon Sep 17 00:00:00 2001 From: James Fantin-Hardesty <24646452+jfantinhardesty@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:53:14 -0600 Subject: [PATCH 2/3] Fix windows function compiler error --- src/lib/cloudfuse/child_process_windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/cloudfuse/child_process_windows.cpp b/src/lib/cloudfuse/child_process_windows.cpp index d4ff95e..113e9e4 100644 --- a/src/lib/cloudfuse/child_process_windows.cpp +++ b/src/lib/cloudfuse/child_process_windows.cpp @@ -60,7 +60,7 @@ std::string getSystemName() std::string systemName; char computerName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = sizeof(computerName) / sizeof(char); - if (GetComputerName(computerName, &size)) + if (GetComputerNameA(computerName, &size)) { systemName = computerName; } From a9bfddf13957d7ea477c63894b49a770648feb38 Mon Sep 17 00:00:00 2001 From: James Fantin-Hardesty <24646452+jfantinhardesty@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:36:45 -0600 Subject: [PATCH 3/3] Fix using no_gui options --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b31966d..f6e0016 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,20 +48,20 @@ jobs: if: ${{ Contains(matrix.os, 'windows') }} shell: pwsh run: | - $download_url = Invoke-RestMethod -Uri "https://api.github.com/repos/Seagate/cloudfuse/releases/latest" | Select-Object -ExpandProperty assets | Where-Object { $_.name -like "*no_gui_windows_amd64.exe" } | Select-Object -ExpandProperty browser_download_url + $download_url = Invoke-RestMethod -Uri "https://api.github.com/repos/Seagate/cloudfuse/releases/latest" | Select-Object -ExpandProperty assets | Where-Object { $_.name -like "*no_gui" -and $_.name -like "*windows_amd64.exe" } | Select-Object -ExpandProperty browser_download_url $file_name = $download_url.Split('/')[-1] Invoke-WebRequest -Uri $download_url -OutFile $file_name - name: Download cloudfuse for Linux amd64 (no_gui) if: ${{ Contains(matrix.os, 'ubuntu') }} run: | - download_url=$(curl -s https://api.github.com/repos/Seagate/cloudfuse/releases/latest | jq -r '.assets[] | select(.name | contains("no_gui_linux_amd64.deb")) | .browser_download_url') + download_url=$(curl -s https://api.github.com/repos/Seagate/cloudfuse/releases/latest | jq -r '.assets[] | select(.name | (contains("no_gui") and contains("linux_amd64.deb"))) | .browser_download_url') curl -LO $download_url - name: Download cloudfuse for Linux arm64 (no_gui) if: ${{ Contains(matrix.os, 'ubuntu') }} run: | - download_url=$(curl -s https://api.github.com/repos/Seagate/cloudfuse/releases/latest | jq -r '.assets[] | select(.name | contains("no_gui_linux_arm64.deb")) | .browser_download_url') + download_url=$(curl -s https://api.github.com/repos/Seagate/cloudfuse/releases/latest | jq -r '.assets[] | select(.name | (contains("no_gui") and contains("linux_arm64.deb"))) | .browser_download_url') curl -LO $download_url - name: Run build script for Linux x64