Commit 1f8c9769 authored by Nathan Bruer's avatar Nathan Bruer Committed by Commit Bot

[Devtools] Changed files now ignored properly in workspaces

If a file is changed on the filesystem and is ignored in devtools it
will now properly not be created in workspaces.

R=lushnikov
BUG=754371

Change-Id: Ic0bc61ede57fb1aa17f1483f614bcca414fe14b6
Reviewed-on: https://chromium-review.googlesource.com/798735
Commit-Queue: Blaise Bruer <allada@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520659}
parent 181073ed
Ensure that if a file that should be ignored is changed on the filesystem it does not propogate events.
Creating filesystem
Creating Files
Creating "ignoredFile"
Created Files:
Changed Files:
Creating "alsoIgnoredFile"
Created Files:
Changed Files:
Creating "friendlyFile"
Created Files:
file:///var/www/friendlyFile
Changed Files:
Modifying "ignoredFile"
Created Files:
Changed Files:
Modifying "alsoIgnoredFile"
Created Files:
Changed Files:
Modifying "friendlyFile"
Created Files:
Changed Files:
file:///var/www/friendlyFile
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(`Ensure that if a file that should be ignored is changed on the filesystem it does not propogate events.\n`);
await TestRunner.loadModule('bindings_test_runner');
TestRunner.addResult('Creating filesystem');
var fs = new BindingsTestRunner.TestFileSystem('file:///var/www');
await fs.reportCreatedPromise();
Persistence.isolatedFileSystemManager.addEventListener(
Persistence.IsolatedFileSystemManager.Events.FileSystemFilesChanged, event => {
TestRunner.addResult('Created Files:');
for (var createdFiles of event.data.added.valuesArray())
TestRunner.addResult(createdFiles);
TestRunner.addResult('');
TestRunner.addResult('Changed Files:');
for (var createdFiles of event.data.changed.valuesArray())
TestRunner.addResult(createdFiles);
TestRunner.addResult('');
});
TestRunner.addResult('Creating Files');
Persistence.isolatedFileSystemManager.workspaceFolderExcludePatternSetting().set('[iI]gnored');
TestRunner.addResult('Creating "ignoredFile"');
var ignoredFile = fs.addFile('ignoredFile', 'content');
TestRunner.addResult('Creating "alsoIgnoredFile"');
var alsoIgnoredFile = fs.addFile('alsoIgnoredFile', 'content');
TestRunner.addResult('Creating "friendlyFile"');
var friendlyFile = fs.addFile('friendlyFile', 'content');
TestRunner.addResult('Modifying "ignoredFile"');
ignoredFile.setContent('content2');
TestRunner.addResult('Modifying "alsoIgnoredFile"');
alsoIgnoredFile.setContent('content2');
TestRunner.addResult('Modifying "friendlyFile"');
friendlyFile.setContent('content2');
TestRunner.completeTest();
})();
\ No newline at end of file
......@@ -161,24 +161,25 @@ Persistence.FileSystemWorkspaceBinding = class {
*/
_fileSystemFilesChanged(event) {
var paths = /** @type {!Persistence.IsolatedFileSystemManager.FilesChangedData} */ (event.data);
forEachFile.call(this, paths.changed, (path, fileSystem) => fileSystem._fileChanged(path));
forEachFile.call(this, paths.added, (path, fileSystem) => fileSystem._fileChanged(path));
forEachFile.call(this, paths.removed, (path, fileSystem) => fileSystem.removeUISourceCode(path));
for (var fileSystemPath of paths.changed.keysArray()) {
var fileSystem = this._boundFileSystems.get(fileSystemPath);
if (!fileSystem)
continue;
paths.changed.get(fileSystemPath).forEach(path => fileSystem._fileChanged(path));
}
/**
* @param {!Array<string>} filePaths
* @param {function(string, !Persistence.FileSystemWorkspaceBinding.FileSystem)} callback
* @this {Persistence.FileSystemWorkspaceBinding}
*/
function forEachFile(filePaths, callback) {
for (var filePath of filePaths) {
for (var fileSystemPath of this._boundFileSystems.keys()) {
var pathPrefix = fileSystemPath.endsWith('/') ? fileSystemPath : fileSystemPath + '/';
if (!filePath.startsWith(pathPrefix))
continue;
callback(filePath, this._boundFileSystems.get(fileSystemPath));
}
}
for (var fileSystemPath of paths.added.keysArray()) {
var fileSystem = this._boundFileSystems.get(fileSystemPath);
if (!fileSystem)
continue;
paths.added.get(fileSystemPath).forEach(path => fileSystem._fileChanged(path));
}
for (var fileSystemPath of paths.removed.keysArray()) {
var fileSystem = this._boundFileSystems.get(fileSystemPath);
if (!fileSystem)
continue;
paths.removed.get(fileSystemPath).forEach(path => fileSystem.removeUISourceCode(path));
}
}
......
......@@ -164,7 +164,7 @@ Persistence.IsolatedFileSystem = class {
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
if (!entry.isDirectory) {
if (this._isFileExcluded(entry.fullPath))
if (this.isFileExcluded(entry.fullPath))
continue;
this._initialFilePaths.add(entry.fullPath.substr(1));
} else {
......@@ -173,7 +173,7 @@ Persistence.IsolatedFileSystem = class {
var parentFolder = entry.fullPath.substring(1, lastSlash);
this._initialGitFolders.add(parentFolder);
}
if (this._isFileExcluded(entry.fullPath + '/'))
if (this.isFileExcluded(entry.fullPath + '/'))
continue;
++pendingRequests;
this._requestEntries(entry.fullPath, boundInnerCallback);
......@@ -558,7 +558,7 @@ Persistence.IsolatedFileSystem = class {
* @param {string} folderPath
* @return {boolean}
*/
_isFileExcluded(folderPath) {
isFileExcluded(folderPath) {
if (this._excludedFolders.has(folderPath))
return true;
var regex = this._manager.workspaceFolderExcludePatternSetting().asRegExp();
......
......@@ -185,12 +185,34 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
* @param {!Common.Event} event
*/
_onFileSystemFilesChanged(event) {
var paths = /** @type {!Persistence.IsolatedFileSystemManager.FilesChangedData} */ (event.data);
var urlPaths = {};
urlPaths.changed = paths.changed.map(embedderPath => Common.ParsedURL.platformPathToURL(embedderPath));
urlPaths.added = paths.added.map(embedderPath => Common.ParsedURL.platformPathToURL(embedderPath));
urlPaths.removed = paths.removed.map(embedderPath => Common.ParsedURL.platformPathToURL(embedderPath));
var urlPaths = {
changed: groupFilePathsIntoFileSystemPaths.call(this, event.data.changed),
added: groupFilePathsIntoFileSystemPaths.call(this, event.data.added),
removed: groupFilePathsIntoFileSystemPaths.call(this, event.data.removed)
};
this.dispatchEventToListeners(Persistence.IsolatedFileSystemManager.Events.FileSystemFilesChanged, urlPaths);
/**
* @param {!Array<string>} embedderPaths
* @return {!Multimap<string, string>}
* @this {Persistence.IsolatedFileSystemManager}
*/
function groupFilePathsIntoFileSystemPaths(embedderPaths) {
var paths = new Multimap();
for (var embedderPath of embedderPaths) {
var filePath = Common.ParsedURL.platformPathToURL(embedderPath);
for (var fileSystemPath of this._fileSystems.keys()) {
if (this._fileSystems.get(fileSystemPath).isFileExcluded(embedderPath))
continue;
var pathPrefix = fileSystemPath.endsWith('/') ? fileSystemPath : fileSystemPath + '/';
if (!filePath.startsWith(pathPrefix))
continue;
paths.set(fileSystemPath, filePath);
}
}
return paths;
}
}
/**
......@@ -319,7 +341,7 @@ Persistence.IsolatedFileSystemManager = class extends Common.Object {
/** @typedef {!{type: string, fileSystemName: string, rootURL: string, fileSystemPath: string}} */
Persistence.IsolatedFileSystemManager.FileSystem;
/** @typedef {!{changed:!Array<string>, added:!Array<string>, removed:!Array<string>}} */
/** @typedef {!{changed:!Multimap<string, string>, added:!Multimap<string, string>, removed:!Multimap<string, string>}} */
Persistence.IsolatedFileSystemManager.FilesChangedData;
/** @enum {symbol} */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment