TagSpaces is an offline, open source, document manager with tagging support
File rename/move now checks if the target file exists.
uggrockd0049069fcc4
diff --git a/lib/ioutils.js b/lib/ioutils.jsindex 0400d056b..6a891fcda 100644--- a/lib/ioutils.js+++ b/lib/ioutils.js@@ -1,4 +1,4 @@-/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.+/* Copyright (c) 2012-2013 The TagSpaces Authors. All rights reserved.* Use of this source code is governed by a AGPL3 license that* can be found in the LICENSE file. */@@ -27,7 +27,7 @@ function getWindow(worker) {}function searchDir(dirPath, index, keewords) {-// console.debug("Indexing directory: "+dirPath);+// console.log("Indexing directory: "+dirPath);var path = "";var isFile = false;try {@@ -54,10 +54,10 @@ function searchDir(dirPath, index, keewords) {}exports.searchDirectory = function searchDirectory(dirPath, keewords, worker) {- console.debug("Searching directory: "+dirPath+" for: "+keewords);+ console.log("Searching directory: "+dirPath+" for: "+keewords);var resultIndex = [];resultIndex = searchDir(dirPath, resultIndex, keewords);-// console.debug("Index: "+JSON.stringify(resultIndex));+// console.log("Index: "+JSON.stringify(resultIndex));worker.postMessage({"command": "indexDirectory","success": true,@@ -66,10 +66,10 @@ exports.searchDirectory = function searchDirectory(dirPath, keewords, worker) {}exports.createDirectoryIndex = function createDirectoryIndex(dirPath, worker) {- console.debug("Creating index for directory: "+dirPath);+ console.log("Creating index for directory: "+dirPath);var directoryIndex = [];directoryIndex = scanDirectory(dirPath, directoryIndex);-// console.debug("Index: "+JSON.stringify(directoryIndex));+// console.log("Index: "+JSON.stringify(directoryIndex));worker.postMessage({"command": "indexDirectory","success": true,@@ -78,9 +78,9 @@ exports.createDirectoryIndex = function createDirectoryIndex(dirPath, worker) {}exports.createDirectoryTree = function createDirectoryTree(dirPath, worker) {- console.debug("Creating directory tree: "+dirPath);+ console.log("Creating directory tree: "+dirPath);var dirTree = directoryTree(dirPath);-// console.debug("Index: "+JSON.stringify(dirTree));+// console.log("Index: "+JSON.stringify(dirTree));worker.postMessage({"command": "createDirectoryTree","success": true,@@ -171,7 +171,7 @@ function scanDirectory(dirPath, index) {// TODO use scanDirectoryexports.listDirectory = function listDirectory(dirPath, worker) {- console.debug("Listing directory: "+dirPath);+ console.log("Listing directory: "+dirPath);try {var dirList = filesIO.list(dirPath);var anotatedDirList = [];@@ -196,7 +196,7 @@ exports.listDirectory = function listDirectory(dirPath, worker) {"success": true,"content": anotatedDirList});- console.debug("Listing directory successful!");+ console.log("Listing directory successful!");} catch(ex) {console.error("Listing directory failed "+ex);worker.postMessage({@@ -207,14 +207,14 @@ exports.listDirectory = function listDirectory(dirPath, worker) {}exports.createDirectory = function createDirectory(filePath, worker) {- console.debug("Creating directory: "+filePath);+ console.log("Creating directory: "+filePath);try {filesIO.mkpath(filePath);worker.postMessage({"command": "createDirectory","success": true});- console.debug("Creating successful!");+ console.log("Creating successful!");} catch(ex) {worker.postMessage({"command": "createDirectory",@@ -225,7 +225,7 @@ exports.createDirectory = function createDirectory(filePath, worker) {}exports.loadTextFile = function loadTextFile(filePath, worker) {- console.debug("Loading text file: "+filePath);+ console.log("Loading text file: "+filePath);try {var content = filesIO.read(filePath);worker.postMessage({@@ -233,7 +233,7 @@ exports.loadTextFile = function loadTextFile(filePath, worker) {"success": true,"content": content});- console.debug("Loading file successful!");+ console.log("Loading file successful!");} catch(ex) {worker.postMessage({"command": "loadTextFile",@@ -244,7 +244,7 @@ exports.loadTextFile = function loadTextFile(filePath, worker) {}exports.getSubdirs = function getSubdirs(dirPath, worker) {- console.debug("Getting subdirectories: "+dirPath);+ console.log("Getting subdirectories: "+dirPath);try {var dirList = filesIO.list(dirPath);var anotatedDirList = [];@@ -253,7 +253,7 @@ exports.getSubdirs = function getSubdirs(dirPath, worker) {var fullPath = filesIO.join(dirPath,dirList[i]);var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsIFile);file.initWithPath(fullPath);- console.debug("File: "+file);+ console.log("File: "+file);if(file.isFile() == false) {anotatedDirList.push({"title": file.leafName,@@ -271,7 +271,7 @@ exports.getSubdirs = function getSubdirs(dirPath, worker) {"success": true,"content": anotatedDirList});- console.debug("Getting subdirectories successful!");+ console.log("Getting subdirectories successful!");} catch(ex) {console.error("Getting subdirectories failed "+ex);worker.postMessage({@@ -282,7 +282,7 @@ exports.getSubdirs = function getSubdirs(dirPath, worker) {}exports.deleteElement = function deleteElement(path, worker) {- console.debug("Deleting: "+path);+ console.log("Deleting: "+path);try {if(filesIO.isFile(path)) {filesIO.remove(path);@@ -290,14 +290,14 @@ exports.deleteElement = function deleteElement(path, worker) {"command": "delete","success": true});- console.debug("Deleting file successful!");+ console.log("Deleting file successful!");} else {filesIO.rmdir(path);worker.postMessage({"command": "delete","success": true});- console.debug("Deleting directory successful!");+ console.log("Deleting directory successful!");}} catch(ex) {worker.postMessage({@@ -309,13 +309,14 @@ exports.deleteElement = function deleteElement(path, worker) {}exports.rename = function rename(filePath, newFilePath, worker) {- console.debug("Renaming file: "+filePath+" to "+newFilePath);+ console.log("Renaming file: "+filePath+" to "+newFilePath);// Checks if the file already exists.-// if(!filesIO.exists(newFilePath)) {+ if(!filesIO.exists(newFilePath)) {try {var targetDir;var targetFileName;// Detecting WINNT os+ console.log("Input filePath: "+filePath+" newFilePath: "+newFilePath);if(runtime.OS.toLowerCase().indexOf("win")!=-1) {targetDir = newFilePath.substring(0,newFilePath.lastIndexOf("\\"));targetFileName = newFilePath.substring(newFilePath.lastIndexOf("\\")+1,newFilePath.length);@@ -323,12 +324,12 @@ exports.rename = function rename(filePath, newFilePath, worker) {targetDir = newFilePath.substring(0,newFilePath.lastIndexOf("/"));targetFileName = newFilePath.substring(newFilePath.lastIndexOf("/")+1,newFilePath.length);}- console.debug("Target dir: "+targetDir+" filename "+targetFileName);+// console.log("Target dir: "+targetDir+" filename: "+targetFileName);var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);file.initWithPath(filePath);var targetDirFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);targetDirFile.initWithPath(targetDir);-// console.debug("After init: "+file.path+" "+targetDirFile.path);+// console.log("After init: "+file.path+" targetdir: "+targetDirFile.path+" targetfilename: "+targetFileName);file.moveTo(targetDirFile,targetFileName);var targetPath = filesIO.join(targetDir,targetFileName);worker.postMessage({@@ -343,17 +344,17 @@ exports.rename = function rename(filePath, newFilePath, worker) {});console.error("Renaming failed "+ex);}-/* } else {+ } else {worker.postMessage({"command": "rename","success": false});console.error("Renaming failed. Target filepath already exists.");- }*/+ }}exports.saveTextFile = function saveTextFile(filePath, content, worker) {- console.debug("Saving file: "+filePath);+ console.log("Saving file: "+filePath);try {var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);file.initWithPath(filePath);@@ -369,7 +370,7 @@ exports.saveTextFile = function saveTextFile(filePath, content, worker) {"content": filePath,"success": true});- console.debug("Save successed!");+ console.log("Save successed!");} catch(ex) {worker.postMessage({"command": "saveTextFile",@@ -385,7 +386,7 @@ exports.saveTextFile = function saveTextFile(filePath, content, worker) {* documentation is https://developer.mozilla.org/en/NsIFilePicker*/exports.promptFileOpenPicker = function promptFileOpenPicker(worker) {- console.debug("Opening file selection dialog");+ console.log("Opening file selection dialog");try {var window = getWindow(worker);var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);@@ -415,7 +416,7 @@ exports.promptFileOpenPicker = function promptFileOpenPicker(worker) {* documentation is https://developer.mozilla.org/en/NsIFilePicker*/exports.promptDirectorySelector = function promptDirectorySelector(worker) {- console.debug("Opening directory selection dialog...");+ console.log("Opening directory selection dialog...");try {// var window = require("window/utils").getMostRecentBrowserWindow();var window = getWindow(worker);@@ -443,7 +444,7 @@ exports.promptDirectorySelector = function promptDirectorySelector(worker) {* http://stackoverflow.com/questions/9453786*/exports.openDirectory = function openDirectory(dirPath, worker) {- console.debug("Opening directory: "+dirPath);+ console.log("Opening directory: "+dirPath);dirPath = "file://"+dirPath;try {var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);@@ -461,7 +462,7 @@ exports.openDirectory = function openDirectory(dirPath, worker) {* This directory is located in the profile with which firefox is started*/exports.openExtensionsDirectory = function openExtensionsDirectory(worker) {- console.debug("Opening extensions directory (not implemented yet)");+ console.log("Opening extensions directory (not implemented yet)");/* try {// Other nsIPropertues such as ProfD could be found on// https://developer.mozilla.org/de/docs/Code_snippets/File_I_O