(source, destination, { replace = false } = {})
| 198 | } |
| 199 | |
| 200 | function copyIntoPlace(source, destination, { replace = false } = {}) { |
| 201 | if (replace) { |
| 202 | mkdirSync(dirname(destination), { recursive: true }); |
| 203 | } else if (existsSync(destination)) { |
| 204 | if (force) { |
| 205 | rmSync(destination, { recursive: true, force: true }); |
| 206 | } else { |
| 207 | return; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | const temporary = `${destination}.tmp-${process.pid}-${Date.now()}`; |
| 212 | rmSync(temporary, { recursive: true, force: true }); |
| 213 | mkdirSync(dirname(temporary), { recursive: true }); |
| 214 | |
| 215 | try { |
| 216 | clonePath(source, temporary); |
| 217 | if (replace) { |
| 218 | rmSync(destination, { recursive: true, force: true }); |
| 219 | } |
| 220 | renameSync(temporary, destination); |
| 221 | } catch (error) { |
| 222 | rmSync(temporary, { recursive: true, force: true }); |
| 223 | if (!bestEffort) { |
| 224 | throw error; |
| 225 | } |
| 226 | console.warn(`[cache] failed to copy ${source}: ${describeError(error)}`); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | function clonePath(source, destination) { |
| 231 | const stats = statSync(source); |
no test coverage detected