Server IP : 85.214.239.14 / Your IP : 3.149.244.92 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/task/2/root/proc/3/cwd/lib/node_modules/npm/node_modules/@npmcli/fs/lib/ |
Upload File : |
const { dirname, join, resolve, relative, isAbsolute } = require('path') const fs = require('fs/promises') const pathExists = async path => { try { await fs.access(path) return true } catch (er) { return er.code !== 'ENOENT' } } const moveFile = async (source, destination, options = {}, root = true, symlinks = []) => { if (!source || !destination) { throw new TypeError('`source` and `destination` file required') } options = { overwrite: true, ...options, } if (!options.overwrite && await pathExists(destination)) { throw new Error(`The destination file exists: ${destination}`) } await fs.mkdir(dirname(destination), { recursive: true }) try { await fs.rename(source, destination) } catch (error) { if (error.code === 'EXDEV' || error.code === 'EPERM') { const sourceStat = await fs.lstat(source) if (sourceStat.isDirectory()) { const files = await fs.readdir(source) await Promise.all(files.map((file) => moveFile(join(source, file), join(destination, file), options, false, symlinks) )) } else if (sourceStat.isSymbolicLink()) { symlinks.push({ source, destination }) } else { await fs.copyFile(source, destination) } } else { throw error } } if (root) { await Promise.all(symlinks.map(async ({ source: symSource, destination: symDestination }) => { let target = await fs.readlink(symSource) // junction symlinks in windows will be absolute paths, so we need to // make sure they point to the symlink destination if (isAbsolute(target)) { target = resolve(symDestination, relative(symSource, target)) } // try to determine what the actual file is so we can create the correct // type of symlink in windows let targetStat = 'file' try { targetStat = await fs.stat(resolve(dirname(symSource), target)) if (targetStat.isDirectory()) { targetStat = 'junction' } } catch { // targetStat remains 'file' } await fs.symlink( target, symDestination, targetStat ) })) await fs.rm(source, { recursive: true, force: true }) } } module.exports = moveFile