-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
83 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#! /usr/bin/env node | ||
|
||
import { homedir } from "os" | ||
import { readdir, lstat, Stats, remove, readFile } from "fs-extra-p" | ||
import { Promise as BluebirdPromise } from "bluebird" | ||
import * as path from "path" | ||
|
||
//noinspection JSUnusedLocalSymbols | ||
const __awaiter = require("./awaiter") | ||
|
||
async function main() { | ||
const dir = path.join(homedir(), ".cache", "fpm") | ||
let items: string[] | null = null | ||
try { | ||
items = await readdir(dir) | ||
} | ||
catch (e) { | ||
if (e.code !== "ENOENT") { | ||
throw e | ||
} | ||
return | ||
} | ||
|
||
await BluebirdPromise.map(items, <(item: string) => BluebirdPromise<any>> (async (it) => { | ||
let stat: Stats | null = null | ||
const itemPath = path.join(dir, it) | ||
try { | ||
stat = await lstat(itemPath) | ||
} | ||
catch (e) { | ||
if (e.code !== "ENOENT") { | ||
throw e | ||
} | ||
return | ||
} | ||
|
||
if (!stat!.isDirectory() || !(await isRecentlyUsed(itemPath))) { | ||
console.log(`remove unused ${itemPath}`) | ||
await remove(itemPath) | ||
} | ||
})) | ||
|
||
await BluebirdPromise.map(items, remove) | ||
} | ||
|
||
async function isRecentlyUsed(dir: string) { | ||
try { | ||
const lastUsed = parseInt(await readFile(path.join(dir, ".lastUsed"), "utf8"), 10) | ||
if (!isNaN(lastUsed) && (Date.now() - lastUsed) < 3600000) { | ||
return true | ||
} | ||
} | ||
catch (e) { | ||
if (e.code !== "ENOENT") { | ||
throw e | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters