source: trip-planner-front/node_modules/@nodelib/fs.scandir/out/providers/async.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.6 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.readdir = exports.readdirWithFileTypes = exports.read = void 0;
4const fsStat = require("@nodelib/fs.stat");
5const rpl = require("run-parallel");
6const constants_1 = require("../constants");
7const utils = require("../utils");
8const common = require("./common");
9function read(directory, settings, callback) {
10 if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
11 readdirWithFileTypes(directory, settings, callback);
12 return;
13 }
14 readdir(directory, settings, callback);
15}
16exports.read = read;
17function readdirWithFileTypes(directory, settings, callback) {
18 settings.fs.readdir(directory, { withFileTypes: true }, (readdirError, dirents) => {
19 if (readdirError !== null) {
20 callFailureCallback(callback, readdirError);
21 return;
22 }
23 const entries = dirents.map((dirent) => ({
24 dirent,
25 name: dirent.name,
26 path: common.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator)
27 }));
28 if (!settings.followSymbolicLinks) {
29 callSuccessCallback(callback, entries);
30 return;
31 }
32 const tasks = entries.map((entry) => makeRplTaskEntry(entry, settings));
33 rpl(tasks, (rplError, rplEntries) => {
34 if (rplError !== null) {
35 callFailureCallback(callback, rplError);
36 return;
37 }
38 callSuccessCallback(callback, rplEntries);
39 });
40 });
41}
42exports.readdirWithFileTypes = readdirWithFileTypes;
43function makeRplTaskEntry(entry, settings) {
44 return (done) => {
45 if (!entry.dirent.isSymbolicLink()) {
46 done(null, entry);
47 return;
48 }
49 settings.fs.stat(entry.path, (statError, stats) => {
50 if (statError !== null) {
51 if (settings.throwErrorOnBrokenSymbolicLink) {
52 done(statError);
53 return;
54 }
55 done(null, entry);
56 return;
57 }
58 entry.dirent = utils.fs.createDirentFromStats(entry.name, stats);
59 done(null, entry);
60 });
61 };
62}
63function readdir(directory, settings, callback) {
64 settings.fs.readdir(directory, (readdirError, names) => {
65 if (readdirError !== null) {
66 callFailureCallback(callback, readdirError);
67 return;
68 }
69 const tasks = names.map((name) => {
70 const path = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
71 return (done) => {
72 fsStat.stat(path, settings.fsStatSettings, (error, stats) => {
73 if (error !== null) {
74 done(error);
75 return;
76 }
77 const entry = {
78 name,
79 path,
80 dirent: utils.fs.createDirentFromStats(name, stats)
81 };
82 if (settings.stats) {
83 entry.stats = stats;
84 }
85 done(null, entry);
86 });
87 };
88 });
89 rpl(tasks, (rplError, entries) => {
90 if (rplError !== null) {
91 callFailureCallback(callback, rplError);
92 return;
93 }
94 callSuccessCallback(callback, entries);
95 });
96 });
97}
98exports.readdir = readdir;
99function callFailureCallback(callback, error) {
100 callback(error);
101}
102function callSuccessCallback(callback, result) {
103 callback(null, result);
104}
Note: See TracBrowser for help on using the repository browser.