Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix to prevent moving files by renaming files using FileTreeView #11862

Merged
merged 4 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/project/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,22 +874,23 @@ define(function (require, exports, module) {
* Rename a file/folder. This will update the project tree data structures
* and send notifications about the rename.
*
* @param {string} oldName Old item name
* @param {string} newName New item name
* @param {string} oldPath Old name of the item with the path
* @param {string} newPath New name of the item with the path
* @param {string} newName New name of the item
* @param {boolean} isFolder True if item is a folder; False if it is a file.
* @return {$.Promise} A promise object that will be resolved or rejected when
* the rename is finished.
*/
function _renameItem(oldName, newName, isFolder) {
function _renameItem(oldPath, newPath, newName, isFolder) {
var result = new $.Deferred();

if (oldName === newName) {
if (oldPath === newPath) {
result.resolve();
} else if (!isValidFilename(FileUtils.getBaseName(newName), _invalidChars)) {
} else if (!isValidFilename(newName, _invalidChars)) {
result.reject(ERROR_INVALID_FILENAME);
} else {
var entry = isFolder ? FileSystem.getDirectoryForPath(oldName) : FileSystem.getFileForPath(oldName);
entry.rename(newName, function (err) {
var entry = isFolder ? FileSystem.getDirectoryForPath(oldPath) : FileSystem.getFileForPath(oldPath);
entry.rename(newPath, function (err) {
if (err) {
result.reject(err);
} else {
Expand All @@ -907,10 +908,11 @@ define(function (require, exports, module) {
* Renames the item at the old path to the new name provided.
*
* @param {string} oldPath full path to the current location of file or directory (should include trailing slash for directory)
* @param {string} newPath full path to the new location of the file or directory
* @param {string} newName new name for the file or directory
*/
ProjectModel.prototype._renameItem = function (oldPath, newName) {
return _renameItem(oldPath, newName, !_pathIsFile(oldPath));
ProjectModel.prototype._renameItem = function (oldPath, newPath, newName) {
return _renameItem(oldPath, newPath, newName, !_pathIsFile(oldPath));
};

/**
Expand Down Expand Up @@ -965,7 +967,7 @@ define(function (require, exports, module) {
renameInfo.deferred.reject(error);
});
} else {
this._renameItem(oldPath, newPath).then(function () {
this._renameItem(oldPath, newPath, newName).then(function () {
finalizeRename();
renameInfo.deferred.resolve({
newPath: newPath
Expand Down Expand Up @@ -1325,7 +1327,7 @@ define(function (require, exports, module) {

// Init invalid characters string
if (brackets.platform === "mac") {
_invalidChars = "?*|:";
_invalidChars = "?*|:/";
} else if (brackets.platform === "linux") {
_invalidChars = "?*|/";
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/ProjectModel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ define(function (require, exports, module) {
expect(vm._treeData.get("subdir1")).toBeUndefined();
expect(vm._treeData.get("somethingelse")).toBeDefined();
expect(vm._treeData.getIn(["somethingelse", "open"])).toBe(true);
expect(model._renameItem).toHaveBeenCalledWith("/foo/subdir1/", "/foo/somethingelse/");
expect(model._renameItem).toHaveBeenCalledWith("/foo/subdir1/", "/foo/somethingelse/", "somethingelse");
});

it("fails for invalid filenames", function () {
Expand Down