From 583fd63a36a20185473a31e7a0b389e912a6c366 Mon Sep 17 00:00:00 2001
From: Skander Hatira <skander.hatira@inrae.fr>
Date: Fri, 1 Oct 2021 15:06:01 +0200
Subject: [PATCH] posix file path style

---
 resources/mongodbMac.yaml                     |  1 -
 src/backend/helpers/createUnits.js            |  1 +
 .../routes/api/comparisonController.js        | 25 +++++++-----
 src/backend/routes/api/runController.js       | 39 +++++++++++++------
 src/components/Comparisons/ComparisonForm.js  |  7 +++-
 src/components/Table/NewTable.js              |  8 ++--
 src/components/Table/Table.js                 |  6 ++-
 7 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/resources/mongodbMac.yaml b/resources/mongodbMac.yaml
index d82a2bd..81c9171 100755
--- a/resources/mongodbMac.yaml
+++ b/resources/mongodbMac.yaml
@@ -13,4 +13,3 @@ dependencies:
   - ncurses=6.2=h0a44026_1
   - openssl=1.1.1h=haf1e3a3_0
   - zlib=1.2.11=h1de35cc_3
-prefix: /Users/shatira/miniconda3/envs/mongodb
diff --git a/src/backend/helpers/createUnits.js b/src/backend/helpers/createUnits.js
index bda48e7..df77e48 100644
--- a/src/backend/helpers/createUnits.js
+++ b/src/backend/helpers/createUnits.js
@@ -3,6 +3,7 @@ const createUnits = (body, uniqueDir) => {
     const fs = require("fs");
     const path = require("path");
     const fields = ["sample", "lane", "techrep", "biorep", "fq1", "fq2"];
+
     const opts = { fields, delimiter: "\t" };
     console.log("creating units");
     if (body.remote) {
diff --git a/src/backend/routes/api/comparisonController.js b/src/backend/routes/api/comparisonController.js
index e7b4063..ff251dd 100644
--- a/src/backend/routes/api/comparisonController.js
+++ b/src/backend/routes/api/comparisonController.js
@@ -31,7 +31,6 @@ router.post("/comparison", (req, res) => {
     } else {
         console.log("made validation");
         if (!req.body.remote) {
-            const date = new Date().getTime().toString();
             const uniqueDir = path.join(
                 req.body.outdir,
                 new Date().getTime().toString()
@@ -100,15 +99,23 @@ router.post("/comparison", (req, res) => {
             //     "../../../bisepsComparison/",
             //     date
             // );
-            const uniqueDir = path.join(
-                req.body.outdir,
-                new Date().getTime().toString()
-            );
-            const uniqueDirRemote = path.join(req.body.remoteDir, date);
+            const uniqueDir = path
+                .join(req.body.outdir, new Date().getTime().toString())
+                .split(path.sep)
+                .join(path.posix.sep);
+            const uniqueDirRemote = path
+                .join(req.body.remoteDir, date)
+                .split(path.sep)
+                .join(path.posix.sep);
             const profile = req.body.cluster
-                ? path.join(uniqueDir, "config/profiles/slurmComparison")
-                : path.join(uniqueDir, "config/profiles/localComparison");
-            const homeDir = path.join(req.body.remoteDir, date);
+                ? path
+                      .join(uniqueDir, "config/profiles/slurmComparison")
+                      .split(path.sep)
+                      .join(path.posix.sep)
+                : path
+                      .join(uniqueDir, "config/profiles/localComparison")
+                      .split(path.sep)
+                      .join(path.posix.sep);
 
             const newComparison = new Comparison({
                 outdir: uniqueDir,
diff --git a/src/backend/routes/api/runController.js b/src/backend/routes/api/runController.js
index c971caf..9e1f2a4 100644
--- a/src/backend/routes/api/runController.js
+++ b/src/backend/routes/api/runController.js
@@ -30,11 +30,14 @@ router.post("/run", (req, res) => {
         return res.status(400).json(errors);
     } else {
         if (!req.body.remote) {
-            const uniqueDir = path.join(
-                req.body.outdir,
-                new Date().getTime().toString()
-            );
-            const profile = path.join(uniqueDir, "config/profiles/local");
+            const uniqueDir = path
+                .join(req.body.outdir, new Date().getTime().toString())
+                .split(path.sep)
+                .join(path.posix.sep);
+            const profile = path
+                .join(uniqueDir, "config/profiles/local")
+                .split(path.sep)
+                .join(path.posix.sep);
 
             const newRun = new Run({
                 params: {
@@ -90,13 +93,28 @@ router.post("/run", (req, res) => {
             spawnChild(req.body, profile, uniqueDir, "", false);
         } else {
             const date = new Date().getTime().toString();
-            const uniqueDir = path.join(req.body.outdir, date);
-            const uniqueDirRemote = path.join(req.body.remoteDir, date);
-            const homeDir = path.join(req.body.remoteDir, date);
+            const uniqueDir = path
+                .join(req.body.outdir, date)
+                .split(path.sep)
+                .join(path.posix.sep);
+            const uniqueDirRemote = path
+                .join(req.body.remoteDir, date)
+                .split(path.sep)
+                .join(path.posix.sep);
+            const homeDir = path
+                .join(req.body.remoteDir, date)
+                .split(path.sep)
+                .join(path.posix.sep);
             console.log(homeDir);
             const profile = req.body.cluster
-                ? path.join(uniqueDir, "config/profiles/slurm")
-                : path.join(uniqueDir, "config/profiles/local");
+                ? path
+                      .join(uniqueDir, "config/profiles/slurm")
+                      .split(path.sep)
+                      .join(path.posix.sep)
+                : path
+                      .join(uniqueDir, "config/profiles/local")
+                      .split(path.sep)
+                      .join(path.posix.sep);
 
             const newRun = new Run({
                 outdir: uniqueDir,
@@ -214,7 +232,6 @@ router.post("/rerun", function (req, res) {
             req.body.cluster ? "config/profiles/slurm" : "config/profiles/local"
         );
         const uniqueDirRemote = req.body.remoteDir;
-        const homeDir = path.join(req.body.remoteDir, uniqueDirRemote);
         spawnChild(
             req.body,
             profile,
diff --git a/src/components/Comparisons/ComparisonForm.js b/src/components/Comparisons/ComparisonForm.js
index ef0f70e..b124ae3 100644
--- a/src/components/Comparisons/ComparisonForm.js
+++ b/src/components/Comparisons/ComparisonForm.js
@@ -300,7 +300,12 @@ export default function ComparisonForm() {
     console.log(e.target.value);
     const newFiles = [];
     for (const file in e.target.value) {
-      newFiles.push(path.join("data/", path.basename(e.target.value[file])));
+      newFiles.push(
+        path
+          .join("data/", path.basename(e.target.value[file]))
+          .split(path.sep)
+          .join(path.posix.sep)
+      );
 
       console.log(e.target.value);
       console.log(newFiles);
diff --git a/src/components/Table/NewTable.js b/src/components/Table/NewTable.js
index c02386d..a5cd988 100644
--- a/src/components/Table/NewTable.js
+++ b/src/components/Table/NewTable.js
@@ -321,10 +321,10 @@ export default function NewTable() {
     console.log(e.target.dataset.idx);
 
     const updatedRemoteUnits = [...remoteunits];
-    updatedRemoteUnits[e.target.dataset.idx][e.target.id] = path.join(
-      "data",
-      path.basename(e.target.files[0].path)
-    );
+    updatedRemoteUnits[e.target.dataset.idx][e.target.id] = path
+      .join("data", path.basename(e.target.files[0].path))
+      .split(path.sep)
+      .join(path.posix.sep);
     setRemoteUnits(updatedRemoteUnits);
 
     updatedUnits[e.target.dataset.idx][e.target.id] = e.target.files[0].path;
diff --git a/src/components/Table/Table.js b/src/components/Table/Table.js
index 6c58a9e..499f44c 100644
--- a/src/components/Table/Table.js
+++ b/src/components/Table/Table.js
@@ -111,7 +111,6 @@ export default function InteractiveList() {
     console.log(row);
     let remotePath = `${row.remoteDir}/${filePath}`;
     let localPath = row.date + filePath;
-    console.log(path.join(bisepsTemp, localPath));
     sftp
       .connect({
         host: row.machine.hostname,
@@ -127,7 +126,10 @@ export default function InteractiveList() {
         console.log(localPath);
         console.log("made it all the way here?");
 
-        return sftp.fastGet(remotePath, path.join(bisepsTemp, localPath));
+        return sftp.fastGet(
+          remotePath,
+          path.join(bisepsTemp, localPath).split(path.sep).join(path.posix.sep)
+        );
       })
       .then((data) => {
         console.log(data);
-- 
GitLab