本文整理汇总了TypeScript中fs.Stats.isSymbolicLink方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Stats.isSymbolicLink方法的具体用法?TypeScript Stats.isSymbolicLink怎么用?TypeScript Stats.isSymbolicLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.Stats
的用法示例。
在下文中一共展示了Stats.isSymbolicLink方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
export const getFileType = (stats: Stats): FileType => {
return stats.isSymbolicLink() ? FileType.SymbolicLink :
stats.isFile() ? FileType.File :
stats.isDirectory() ? FileType.Directory :
stats.isBlockDevice() ? FileType.BlockDevice :
stats.isCharacterDevice() ? FileType.CharacterDevice :
stats.isFIFO() ? FileType.FIFO :
stats.isSocket() ? FileType.Socket :
FileType.Other;
};
示例2: safeLink
async function safeLink(existingPath: string, newPath: string, stat: Stats) {
try {
await fs.link(existingPath, newPath)
} catch (err) {
// shouldn't normally happen, but if the file was already somehow linked,
// the installation should not fail
if (err.code === 'EEXIST') {
return
}
// might happen if package contains a broken symlink, we don't fail on this
if (err.code === 'ENOENT' && stat.isSymbolicLink()) {
logger.warn({
message: `Broken symlink found: ${existingPath}`,
})
return
}
throw err
}
}
示例3: saveCachedResolution
async function saveCachedResolution (): Promise<FetchedPackage> {
const target = path.join(modules, spec.name)
const stat: Stats = await fs.lstat(target)
if (stat.isSymbolicLink()) {
const linkPath = await fs.readlink(target)
return save(path.resolve(linkPath, target))
}
return save(target)
async function save (fullpath: string): Promise<FetchedPackage> {
const data = await requireJson(path.join(fullpath, 'package.json'))
return {
fetchingPkg: Promise.resolve(data),
fetchingFiles: Promise.resolve(),
id: path.basename(fullpath),
fromCache: true,
path: fullpath,
abort: () => Promise.resolve(),
}
}
}
示例4: get_listing
export async function get_listing(
path: string,
hidden: boolean = false
): Promise<ListingEntry[]> {
const dir = HOME + "/" + path;
const files: ListingEntry[] = [];
let name: string;
for (name of await callback(readdir, dir)) {
if (!hidden && name[0] === ".") {
continue;
}
let entry: ListingEntry;
try {
// I don't actually know if file can fail to be JSON-able with node.js -- is there
// even a string in Node.js that cannot be dumped to JSON? With python
// this definitely was a problem, but I can't find the examples now. Users
// sometimes create "insane" file names via bugs in C programs...
JSON.stringify(name);
entry = { name };
} catch (err) {
entry = { name: "????", error: "Cannot display bad binary filename. " };
}
let stats: Stats;
try {
stats = await callback(lstat, dir + "/" + entry.name);
if (stats.isSymbolicLink()) {
entry.issymlink = true;
try {
stats = await callback(stat, dir + "/" + entry.name);
} catch (err) {
// broken link -- just report info about the link itself...
}
}
entry.mtime = stats.mtime.valueOf() / 1000;
if (stats.isDirectory()) {
entry.isdir = true;
try {
const v = await callback(readdir, dir + "/" + entry.name);
if (hidden) {
entry.size = v.length;
} else {
// only count non-hidden files
entry.size = 0;
for (let x of v) {
if (x[0] != ".") {
entry.size += 1;
}
}
}
} catch (err) {
// just ignore -- no size info.
}
} else {
entry.size = stats.size;
}
} catch (err) {
entry.error = `${entry.error ? entry.error : ""}${err}`;
}
files.push(entry);
}
return files;
}