Handle symlinks when unzipping & updating datasets repositories
This commit is contained in:
parent
50691e6da1
commit
18ba4b59b0
2 changed files with 25 additions and 2 deletions
|
@ -12,7 +12,7 @@ export function* walkDir(
|
||||||
}
|
}
|
||||||
const filePath = path.join(dir, filename)
|
const filePath = path.join(dir, filename)
|
||||||
const relativeSplitPath = [...relativeSplitDir, filename]
|
const relativeSplitPath = [...relativeSplitDir, filename]
|
||||||
if (fs.statSync(filePath).isDirectory()) {
|
if (fs.lstatSync(filePath).isDirectory()) {
|
||||||
yield* walkDir(rootDir, relativeSplitPath)
|
yield* walkDir(rootDir, relativeSplitPath)
|
||||||
} else {
|
} else {
|
||||||
yield relativeSplitPath
|
yield relativeSplitPath
|
||||||
|
|
|
@ -5,6 +5,8 @@ import path from "path"
|
||||||
import sade from "sade"
|
import sade from "sade"
|
||||||
import { $, cd } from "zx"
|
import { $, cd } from "zx"
|
||||||
|
|
||||||
|
import { walkDir } from "$lib/server/file_systems"
|
||||||
|
|
||||||
async function downloadDataset(
|
async function downloadDataset(
|
||||||
datasetName: string,
|
datasetName: string,
|
||||||
dilaDir: string,
|
dilaDir: string,
|
||||||
|
@ -99,7 +101,28 @@ async function downloadDataset(
|
||||||
", ",
|
", ",
|
||||||
)}`,
|
)}`,
|
||||||
)
|
)
|
||||||
await $`cp -r ${date}/${datasetName}/* ${datasetName}/`
|
|
||||||
|
// When archive contains a symbolic link and dataset contains at the same path
|
||||||
|
// something that is not a symbolic link, remove it before copy, otherwise
|
||||||
|
// copy of symbolic link will fail.
|
||||||
|
const archiveDatasetDir = path.join(date, datasetName)
|
||||||
|
for (const relativeSplitPath of walkDir(archiveDatasetDir)) {
|
||||||
|
const archiveFilePath = path.join(
|
||||||
|
archiveDatasetDir,
|
||||||
|
...relativeSplitPath,
|
||||||
|
)
|
||||||
|
if (fs.lstatSync(archiveFilePath).isSymbolicLink()) {
|
||||||
|
const datasetFilePath = path.join(datasetName, ...relativeSplitPath)
|
||||||
|
if (
|
||||||
|
fs.pathExistsSync(datasetFilePath) &&
|
||||||
|
!fs.lstatSync(datasetFilePath).isSymbolicLink()
|
||||||
|
) {
|
||||||
|
fs.removeSync(datasetFilePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await $`cp -r ${archiveDatasetDir}/* ${datasetName}/`
|
||||||
const removalListFilePath = path.join(
|
const removalListFilePath = path.join(
|
||||||
date,
|
date,
|
||||||
`liste_suppression_${datasetName}.dat`,
|
`liste_suppression_${datasetName}.dat`,
|
||||||
|
|
Loading…
Reference in a new issue