forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileIndex.js
More file actions
1 lines (1 loc) · 2.11 KB
/
Copy pathFileIndex.js
File metadata and controls
1 lines (1 loc) · 2.11 KB
1
define(function(require,exports,module){var FileUtils=require("file/FileUtils");function FileIndex(){this._index={},this._doNotRemoveItems={}}FileIndex.prototype._index=null,FileIndex.prototype._doNotRemoveItems=null,FileIndex.prototype.clear=function(){this._index={},this._doNotRemoveItems={}},FileIndex.prototype.doNotRemoveFromIndex=function(filePath){this._doNotRemoveItems[filePath]=!0},FileIndex.prototype.visitAll=function(visitor){var path;for(path in this._index)this._index.hasOwnProperty(path)&&visitor(this._index[path],path)},FileIndex.prototype.addEntry=function(entry){this._index[entry.fullPath]=entry},FileIndex.prototype.removeEntry=function(entry){var path=entry.fullPath,property;if(!this._doNotRemoveItems[path])for(property in delete this._index[path],entry)entry.hasOwnProperty(property)&&replaceMember(property);function replaceMember(property){var member=entry[property];"function"==typeof member&&(entry[property]=function(){return console.warn("FileSystemEntry used after being removed from index: ",path),member.apply(entry,arguments)})}},FileIndex.prototype.entryRenamed=function(oldPath,newPath,isDirectory){var path,renameMap={},oldParentPath=FileUtils.getParentPath(oldPath),newParentPath=FileUtils.getParentPath(newPath);for(path in this._index)this._index.hasOwnProperty(path)&&(isDirectory?0===path.indexOf(oldPath):path===oldPath)&&(renameMap[path]=newPath+path.substr(oldPath.length));for(path in renameMap)if(renameMap.hasOwnProperty(path)){var item=this._index[path];console.assert(item.fullPath===path),delete this._index[path],this._index[renameMap[path]]=item,item._setPath(renameMap[path])}if(oldParentPath!==newParentPath){var oldDirectory=this._index[oldParentPath],newDirectory=this._index[newParentPath],renamedEntry;oldDirectory&&oldDirectory._contents&&(oldDirectory._contents=oldDirectory._contents.filter(function(entry){return entry.fullPath!==newPath||(renamedEntry=entry,!1)})),newDirectory&&newDirectory._contents&&renamedEntry&&(renamedEntry._setPath(newPath),newDirectory._contents.push(renamedEntry))}},FileIndex.prototype.getEntry=function(path){return this._index[path]},module.exports=FileIndex});