fallback to stat if lstat fails

#44543
This commit is contained in:
isidor 2018-02-27 16:31:19 +01:00
parent 5265944563
commit de292c2ff7

View file

@ -49,21 +49,17 @@ export interface IStatAndLink {
}
export function statLink(path: string, callback: (error: Error, statAndIsLink: IStatAndLink) => void): void {
fs.lstat(path, (error, stat) => {
if (error) {
return callback(error, null);
}
if (stat.isSymbolicLink()) {
fs.lstat(path, (error, lstat) => {
if (error || lstat.isSymbolicLink()) {
fs.stat(path, (error, stat) => {
if (error) {
return callback(error, null);
}
callback(null, { stat, isSymbolicLink: true });
callback(null, { stat, isSymbolicLink: lstat && lstat.isSymbolicLink() });
});
} else {
callback(null, { stat, isSymbolicLink: false });
callback(null, { stat: lstat, isSymbolicLink: false });
}
});
}