From 2d3851282a0ed494a89168a55540cf69609c3af4 Mon Sep 17 00:00:00 2001 From: Travis Glenn Hansen Date: Fri, 6 May 2022 19:23:19 -0600 Subject: [PATCH] minor fixes Signed-off-by: Travis Glenn Hansen --- bin/democratic-csi | 3 ++- ci/bin/run.sh | 2 +- src/driver/freenas/api.js | 2 +- src/driver/index.js | 35 +++++++---------------------------- src/utils/filesystem.js | 21 +++++++++++++-------- src/utils/windows.js | 8 +++++++- 6 files changed, 31 insertions(+), 40 deletions(-) diff --git a/bin/democratic-csi b/bin/democratic-csi index 254ebb2..7d2e0ad 100755 --- a/bin/democratic-csi +++ b/bin/democratic-csi @@ -372,9 +372,10 @@ if (args.serverSocket) { } logger.info( - "starting csi server - node version: %s, package version: %s, csi-name: %s, csi-driver: %s, csi-mode: %s, csi-version: %s, address: %s, socket: %s", + "starting csi server - node version: %s, package version: %s, config file: %s, csi-name: %s, csi-driver: %s, csi-mode: %s, csi-version: %s, address: %s, socket: %s", process.version, args.version, + fs.realpathSync(args.driverConfigFile), args.csiName, options.driver, args.csiMode.join(","), diff --git a/ci/bin/run.sh b/ci/bin/run.sh index b16a92a..1d4eaf8 100755 --- a/ci/bin/run.sh +++ b/ci/bin/run.sh @@ -15,7 +15,7 @@ export PATH="/usr/local/lib/nodejs/bin:${PATH}" # install deps #npm i # install from artifacts -if [[ -f "node_modules-linux-amd64.tar.gz" ]];then +if [[ -f "node_modules-linux-amd64.tar.gz" && ! -d "node_modules" ]];then tar -zxf node_modules-linux-amd64.tar.gz fi diff --git a/src/driver/freenas/api.js b/src/driver/freenas/api.js index 8af3853..241ea7e 100644 --- a/src/driver/freenas/api.js +++ b/src/driver/freenas/api.js @@ -1476,7 +1476,7 @@ class FreeNASApiDriver extends CsiBaseDriver { break; case "iscsi": // Delete target - // NOTE: deletting a target inherently deletes associated targetgroup(s) and targettoextent(s) + // NOTE: deleting a target inherently deletes associated targetgroup(s) and targettoextent(s) // Delete extent try { diff --git a/src/driver/index.js b/src/driver/index.js index 8a68fc8..23b30fd 100644 --- a/src/driver/index.js +++ b/src/driver/index.js @@ -1258,16 +1258,7 @@ class CsiBaseDriver { * * if path exists but is NOT symlink delete it */ - try { - fs.statSync(win_staging_target_path); - result = true; - } catch (err) { - if (err.code === "ENOENT") { - result = false; - } else { - throw err; - } - } + result = await filesystem.pathExists(win_staging_target_path); if (result) { result = fs.lstatSync(win_staging_target_path); @@ -1593,22 +1584,10 @@ class CsiBaseDriver { } break; case "hostpath": - try { - fs.statSync(win_staging_target_path); - result = true; - } catch (err) { - if (err.code === "ENOENT") { - result = false; - } else { - throw err; - } - } - // if exists already delete if folder, return if symlink - if (result) { - result = fs.lstatSync(win_staging_target_path); + if (await filesystem.pathExists(win_staging_target_path)) { // remove pre-created dir by CO - if (!result.isSymbolicLink()) { + if (!(await filesystem.isSymbolicLink(win_staging_target_path))) { fs.rmdirSync(win_staging_target_path); } else { // assume symlink points to the correct location @@ -2627,7 +2606,7 @@ class CsiBaseDriver { ); // source path - result = await wutils.GetItem(normalized_staging_path); + result = await filesystem.pathExists(normalized_staging_path); if (!result) { throw new GrpcError( grpc.status.FAILED_PRECONDITION, @@ -2982,7 +2961,7 @@ class CsiBaseDriver { let win_volume_path = filesystem.covertUnixSeparatorToWindowsSeparator(volume_path); // ensure path is mounted - result = await wutils.GetItem(win_volume_path); + result = await filesystem.pathExists(win_volume_path); if (!result) { throw new GrpcError( grpc.status.NOT_FOUND, @@ -2992,7 +2971,7 @@ class CsiBaseDriver { let node_attach_driver; - let target = await wutils.GetRealTarget(win_volume_path) || ""; + let target = (await wutils.GetRealTarget(win_volume_path)) || ""; if (target.startsWith("\\\\")) { node_attach_driver = "smb"; } @@ -3236,7 +3215,7 @@ class CsiBaseDriver { filesystem.covertUnixSeparatorToWindowsSeparator(volume_path); // ensure path is mounted - result = await wutils.GetItem(win_volume_path); + result = filesystem.pathExists(win_volume_path); if (!result) { throw new GrpcError( grpc.status.NOT_FOUND, diff --git a/src/utils/filesystem.js b/src/utils/filesystem.js index d6fdbb9..de4bce7 100644 --- a/src/utils/filesystem.js +++ b/src/utils/filesystem.js @@ -228,8 +228,12 @@ class Filesystem { } } + async isSymboliclink(path) { + return fs.lstatSync(path).isSymbolicLink(); + } + /** - * create symlink + * remove file * * @param {*} device */ @@ -829,16 +833,17 @@ class Filesystem { * @param {*} path */ async pathExists(path) { - const filesystem = this; - let args = []; - args.push(path); - + let result = false; try { - await filesystem.exec("stat", args); + fs.statSync(path); + result = true; } catch (err) { - return false; + if (err.code !== "ENOENT") { + throw err; + } } - return true; + + return result; } exec(command, args, options = {}) { diff --git a/src/utils/windows.js b/src/utils/windows.js index 6f2d853..7b591c3 100644 --- a/src/utils/windows.js +++ b/src/utils/windows.js @@ -60,6 +60,7 @@ class Windows { } } while (path); } + async GetItem(localPath) { let command; let result; @@ -201,7 +202,12 @@ class Windows { chapSecret, multipath = false ) { - let is_connected = await this.IscsiTargetIsConnectedByPortalAddressPortalPort(address, port, iqn); + let is_connected = + await this.IscsiTargetIsConnectedByPortalAddressPortalPort( + address, + port, + iqn + ); if (is_connected) { return; }