mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
refactor: copy geodata only if source files are newer
This commit is contained in:
parent
ef96819621
commit
f56c585818
@ -82,6 +82,18 @@ async function fixDataDirPermissions(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 比较修改geodata文件修改时间
|
||||||
|
async function isSourceNewer(sourcePath: string, targetPath: string): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
const sourceStats = await stat(sourcePath)
|
||||||
|
const targetStats = await stat(targetPath)
|
||||||
|
|
||||||
|
return sourceStats.mtime > targetStats.mtime
|
||||||
|
} catch {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function initDirs(): Promise<void> {
|
async function initDirs(): Promise<void> {
|
||||||
await fixDataDirPermissions()
|
await fixDataDirPermissions()
|
||||||
|
|
||||||
@ -137,11 +149,18 @@ async function initFiles(): Promise<void> {
|
|||||||
const sourcePath = path.join(resourcesFilesDir(), file)
|
const sourcePath = path.join(resourcesFilesDir(), file)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!existsSync(targetPath) && existsSync(sourcePath)) {
|
// 检查是否需要复制
|
||||||
await cp(sourcePath, targetPath, { recursive: true })
|
if (existsSync(sourcePath)) {
|
||||||
|
const shouldCopyToWork = !existsSync(targetPath) || await isSourceNewer(sourcePath, targetPath)
|
||||||
|
if (shouldCopyToWork) {
|
||||||
|
await cp(sourcePath, targetPath, { recursive: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!existsSync(testTargetPath) && existsSync(sourcePath)) {
|
if (existsSync(sourcePath)) {
|
||||||
await cp(sourcePath, testTargetPath, { recursive: true })
|
const shouldCopyToTest = !existsSync(testTargetPath) || await isSourceNewer(sourcePath, testTargetPath)
|
||||||
|
if (shouldCopyToTest) {
|
||||||
|
await cp(sourcePath, testTargetPath, { recursive: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to copy ${file}:`, error)
|
console.error(`Failed to copy ${file}:`, error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user