]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - cli/actions.js
fix path resolution
[perso/Immae/Projets/Nodejs/Surfer.git] / cli / actions.js
index e5b0c6ddc3a8f0a00324679967c2cade7bfc755a..735b631600092ef4054895bd1577d9ffca22cb97 100644 (file)
@@ -93,11 +93,19 @@ function put(filePath, otherFilePaths, options) {
     var files = collectFiles([ filePath ].concat(otherFilePaths));
 
     async.eachSeries(files, function (file, callback) {
-        var relativeFilePath = path.resolve(file).slice(process.cwd().length + 1);
+        var relativeFilePath;
+        if (path.isAbsolute(file)) {
+            relativeFilePath = path.basename(file);
+        } else if (path.resolve(file).indexOf(process.cwd().length) === 0) { // relative to current dir
+            relativeFilePath = path.resolve(file).slice(process.cwd().length + 1);
+        } else { // relative but somewhere else
+            relativeFilePath = path.basename(file);
+        }
+
         var destinationPath = (options.destination ? '/' + options.destination : '') + '/' + relativeFilePath;
         console.log('Uploading file %s -> %s', relativeFilePath.cyan, destinationPath.cyan);
 
-        superagent.put(config.server() + API + relativeFilePath).query(gQuery).attach('file', file).end(function (error, result) {
+        superagent.put(config.server() + API + destinationPath).query(gQuery).attach('file', file).end(function (error, result) {
             if (error) return callback(error);
             if (result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode));