Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
698 bytes
|
Line | |
---|
1 | 'use strict'
|
---|
2 |
|
---|
3 | const fs = require('graceful-fs')
|
---|
4 |
|
---|
5 | function symlinkType (srcpath, type, callback) {
|
---|
6 | callback = (typeof type === 'function') ? type : callback
|
---|
7 | type = (typeof type === 'function') ? false : type
|
---|
8 | if (type) return callback(null, type)
|
---|
9 | fs.lstat(srcpath, (err, stats) => {
|
---|
10 | if (err) return callback(null, 'file')
|
---|
11 | type = (stats && stats.isDirectory()) ? 'dir' : 'file'
|
---|
12 | callback(null, type)
|
---|
13 | })
|
---|
14 | }
|
---|
15 |
|
---|
16 | function symlinkTypeSync (srcpath, type) {
|
---|
17 | let stats
|
---|
18 |
|
---|
19 | if (type) return type
|
---|
20 | try {
|
---|
21 | stats = fs.lstatSync(srcpath)
|
---|
22 | } catch (e) {
|
---|
23 | return 'file'
|
---|
24 | }
|
---|
25 | return (stats && stats.isDirectory()) ? 'dir' : 'file'
|
---|
26 | }
|
---|
27 |
|
---|
28 | module.exports = {
|
---|
29 | symlinkType,
|
---|
30 | symlinkTypeSync
|
---|
31 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.