Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: pkg/watcher/lib/src/path_set.dart

Issue 428493004: Add check to watcher, to avoid null-error if unknown path is removed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library watcher.path_dart; 5 library watcher.path_dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Remove the children of [dir], as well as [dir] itself if necessary. 64 // Remove the children of [dir], as well as [dir] itself if necessary.
65 // 65 //
66 // [partialPath] is the path to [dir], and a prefix of [path]; the remaining 66 // [partialPath] is the path to [dir], and a prefix of [path]; the remaining
67 // components of [path] are in [parts]. 67 // components of [path] are in [parts].
68 recurse(dir, partialPath) { 68 recurse(dir, partialPath) {
69 if (parts.length > 1) { 69 if (parts.length > 1) {
70 // If there's more than one component left in [path], recurse down to 70 // If there's more than one component left in [path], recurse down to
71 // the next level. 71 // the next level.
72 var part = parts.removeFirst(); 72 var part = parts.removeFirst();
73 var entry = dir[part]; 73 var entry = dir[part];
74 if (entry.isEmpty) return new Set(); 74 if (entry == null || entry.isEmpty) return new Set();
75 75
76 partialPath = p.join(partialPath, part); 76 partialPath = p.join(partialPath, part);
77 var paths = recurse(entry, partialPath); 77 var paths = recurse(entry, partialPath);
78 // After removing this entry's children, if it has no more children and 78 // After removing this entry's children, if it has no more children and
79 // it's not in the set in its own right, remove it as well. 79 // it's not in the set in its own right, remove it as well.
80 if (entry.isEmpty && !_paths.contains(partialPath)) dir.remove(part); 80 if (entry.isEmpty && !_paths.contains(partialPath)) dir.remove(part);
81 return paths; 81 return paths;
82 } 82 }
83 83
84 // If there's only one component left in [path], we should remove it. 84 // If there's only one component left in [path], we should remove it.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // 14980). 159 // 14980).
160 if (!p.isRelative(relative) || parts.first == '..' || parts.first == '.') { 160 if (!p.isRelative(relative) || parts.first == '..' || parts.first == '.') {
161 throw new ArgumentError('Path "$path" is not inside "$root".'); 161 throw new ArgumentError('Path "$path" is not inside "$root".');
162 } 162 }
163 return p.join(root, relative); 163 return p.join(root, relative);
164 } 164 }
165 165
166 /// Returns the segments of [path] beneath [root]. 166 /// Returns the segments of [path] beneath [root].
167 List<String> _split(String path) => p.split(p.relative(path, from: root)); 167 List<String> _split(String path) => p.split(p.relative(path, from: root));
168 } 168 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698