@@ -248,14 +248,30 @@ define(function (require, exports, module) {
248248 }
249249
250250 /**
251+ * Checks wheter a path is affected by a rename operation.
252+ * A path is affected if the object being renamed is a file and the given path refers
253+ * to that file or if the object being renamed is a directory and a prefix of the path.
254+ * Always checking for prefixes can create conflicts:
255+ * renaming file "foo" should not affect file "foobar/baz" even though "foo" is a prefix of "foobar".
256+ * @param {!string } path The path potentially affected
257+ * @param {!string } oldName An object's name before renaming
258+ * @param {!string } newName An object's name after renaming
259+ * @param {?boolean } isFolder Whether the renamed object is a folder or not
260+ */
261+ function isAffectedWhenRenaming ( path , oldName , newName , isFolder ) {
262+ isFolder = isFolder || oldName . slice ( - 1 ) === "/" ;
263+ return ( isFolder && path . indexOf ( oldName ) === 0 ) || ( ! isFolder && path === oldName ) ;
264+ }
265+
266+ /**
251267 * Update a file entry path after a file/folder name change.
252268 * @param {FileEntry } entry The FileEntry or DirectoryEntry to update
253269 * @param {string } oldName The full path of the old name
254270 * @param {string } newName The full path of the new name
255271 * @return {boolean } Returns true if the file entry was updated
256272 */
257- function updateFileEntryPath ( entry , oldName , newName ) {
258- if ( entry . fullPath . indexOf ( oldName ) === 0 ) {
273+ function updateFileEntryPath ( entry , oldName , newName , isFolder ) {
274+ if ( isAffectedWhenRenaming ( entry . fullPath , oldName , newName , isFolder ) ) {
259275 var fullPath = entry . fullPath . replace ( oldName , newName ) ;
260276
261277 entry . fullPath = fullPath ;
@@ -276,7 +292,7 @@ define(function (require, exports, module) {
276292
277293 return false ;
278294 }
279-
295+
280296 /** @const - hard-coded for now, but may want to make these preferences */
281297 var _staticHtmlFileExts = [ "htm" , "html" ] ,
282298 _serverHtmlFileExts = [ "php" , "php3" , "php4" , "php5" , "phtm" , "phtml" , "cfm" , "cfml" , "asp" , "aspx" , "jsp" , "jspx" , "shtm" , "shtml" ] ;
@@ -327,6 +343,7 @@ define(function (require, exports, module) {
327343 exports . getNativeBracketsDirectoryPath = getNativeBracketsDirectoryPath ;
328344 exports . getNativeModuleDirectoryPath = getNativeModuleDirectoryPath ;
329345 exports . canonicalizeFolderPath = canonicalizeFolderPath ;
346+ exports . isAffectedWhenRenaming = isAffectedWhenRenaming ;
330347 exports . updateFileEntryPath = updateFileEntryPath ;
331348 exports . isStaticHtmlFileExt = isStaticHtmlFileExt ;
332349 exports . isServerHtmlFileExt = isServerHtmlFileExt ;
0 commit comments