You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.0 KiB

4 years ago
  1. # move-concurrently
  2. Move files and directories.
  3. ```
  4. const move = require('move-concurrently')
  5. move('/path/to/thing', '/new/path/thing').then(() => {
  6. // thing is now moved!
  7. }).catch(err => {
  8. // oh no!
  9. })
  10. ```
  11. Uses `rename` to move things as fast as possible.
  12. If you `move` across devices or on filesystems that don't support renaming
  13. large directories. That is, situations that result in `rename` returning
  14. the `EXDEV` error, then `move` will fallback to copy + delete.
  15. When recursively copying directories it will first try to rename the
  16. contents before falling back to copying. While this will be slightly slower
  17. in true cross-device scenarios, it is MUCH faster in cases where the
  18. filesystem can't handle directory renames.
  19. When copying ownership is maintained when running as root. Permissions are
  20. always maintained. On Windows, if symlinks are unavailable then junctions
  21. will be used.
  22. ## INTERFACE
  23. ### move(from, to, options) → Promise
  24. Recursively moves `from` to `to` and resolves its promise when finished.
  25. If `to` already exists then the promise will be rejected with an `EEXIST`
  26. error.
  27. Starts by trying to rename `from` to `to`.
  28. Options are:
  29. * maxConcurrency – (Default: `1`) The maximum number of concurrent copies to do at once.
  30. * isWindows - (Default: `process.platform === 'win32'`) If true enables Windows symlink semantics. This requires
  31. an extra `stat` to determine if the destination of a symlink is a file or directory. If symlinking a directory
  32. fails then we'll try making a junction instead.
  33. Options can also include dependency injection:
  34. * Promise - (Default: `global.Promise`) The promise implementation to use, defaults to Node's.
  35. * fs - (Default: `require('fs')`) The filesystem module to use. Can be used
  36. to use `graceful-fs` or to inject a mock.
  37. * writeStreamAtomic - (Default: `require('fs-write-stream-atomic')`) The
  38. implementation of `writeStreamAtomic` to use. Used to inject a mock.
  39. * getuid - (Default: `process.getuid`) A function that returns the current UID. Used to inject a mock.