|
1 |
| -import * as fs from "fs"; |
| 1 | +import { Stats } from "fs"; |
2 | 2 | import * as path from "path";
|
3 | 3 | import {
|
4 | 4 | commands,
|
@@ -31,6 +31,7 @@ import {
|
31 | 31 | isDescendant,
|
32 | 32 | normalizePath
|
33 | 33 | } from "./util";
|
| 34 | +import { exists, readDir, stat } from "./util/async_fs"; |
34 | 35 | import { matchAll } from "./util/globMatch";
|
35 | 36 |
|
36 | 37 | export class Model implements IDisposable {
|
@@ -269,15 +270,27 @@ export class Model implements IDisposable {
|
269 | 270 | return;
|
270 | 271 | }
|
271 | 272 |
|
272 |
| - let isSvnFolder = fs.existsSync(path + "/.svn"); |
| 273 | + let isSvnFolder = false; |
| 274 | + |
| 275 | + try { |
| 276 | + isSvnFolder = await exists(path + "/.svn"); |
| 277 | + } catch (error) { |
| 278 | + // error |
| 279 | + } |
273 | 280 |
|
274 | 281 | // If open only a subpath.
|
275 | 282 | if (!isSvnFolder && level === 0) {
|
276 | 283 | const pathParts = path.split(/[\\/]/);
|
277 | 284 | while (pathParts.length > 0) {
|
278 | 285 | pathParts.pop();
|
279 | 286 | const topPath = pathParts.join("/") + "/.svn";
|
280 |
| - isSvnFolder = fs.existsSync(topPath); |
| 287 | + |
| 288 | + try { |
| 289 | + isSvnFolder = await exists(topPath); |
| 290 | + } catch (error) { |
| 291 | + // error |
| 292 | + } |
| 293 | + |
281 | 294 | if (isSvnFolder) {
|
282 | 295 | break;
|
283 | 296 | }
|
@@ -320,11 +333,26 @@ export class Model implements IDisposable {
|
320 | 333 |
|
321 | 334 | const newLevel = level + 1;
|
322 | 335 | if (newLevel <= this.maxDepth) {
|
323 |
| - for (const file of fs.readdirSync(path)) { |
| 336 | + let files: string[] | Buffer[] = []; |
| 337 | + |
| 338 | + try { |
| 339 | + files = await readDir(path); |
| 340 | + } catch (error) { |
| 341 | + return; |
| 342 | + } |
| 343 | + |
| 344 | + for (const file of files) { |
324 | 345 | const dir = path + "/" + file;
|
| 346 | + let stats: Stats; |
| 347 | + |
| 348 | + try { |
| 349 | + stats = await stat(dir); |
| 350 | + } catch (error) { |
| 351 | + continue; |
| 352 | + } |
325 | 353 |
|
326 | 354 | if (
|
327 |
| - fs.statSync(dir).isDirectory() && |
| 355 | + stats.isDirectory() && |
328 | 356 | !matchAll(dir, this.ignoreList, { dot: true })
|
329 | 357 | ) {
|
330 | 358 | await this.tryOpenRepository(dir, newLevel);
|
|
0 commit comments