Skip to content

Commit

Permalink
修正Windows下gc会删除所有文件
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Jun 5, 2021
1 parent 5f4e696 commit 4621aff
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {NextFunction, Request, Response} from 'express'
import {outputFile, pathExists, readdir, stat, unlink} from 'fs-extra'
import got, {Got} from 'got'
import {createServer, Server} from 'http'
import {join} from 'path'
import {join, sep} from 'path'
import * as ProgressBar from 'progress'
import * as io from 'socket.io-client'
import clone = require('lodash.clone')
Expand Down Expand Up @@ -262,7 +262,7 @@ export class Cluster {
private async gc(fileList: IFileList): Promise<void> {
const fileSet = new Set<string>()
for (const file of fileList.files) {
fileSet.add(`/${this.hashToFilename(file.hash)}`)
fileSet.add(`${this.hashToFilename(file.hash)}`)
}
const queue = [this.cacheDir]
do {
Expand All @@ -275,7 +275,8 @@ export class Cluster {
queue.push(p)
continue
}
if (!fileSet.has(p.replace(this.cacheDir, ''))) {
const cacheDirWithSep = this.cacheDir + sep
if (!fileSet.has(p.replace(cacheDirWithSep, ''))) {
console.log(colors.gray(`delete expire file: ${p}`))
await unlink(p)
}
Expand Down

0 comments on commit 4621aff

Please sign in to comment.