[
  {
    "path": ".github/issue_template.md",
    "content": "<!-- First ensure you installed the latest version of fs-extra -->\n<!-- If your bug still exists please fill out the following information if it applies to your issue: -->\n<!-- Please check if you have installed a supported version of Node.js as written in \"engines\" in the package.json -->\n- **Operating System:**\n- **Node.js version:**\n- **`fs-extra` version:**\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: Node.js CI\non:\n  push:\n    branches: master\n  pull_request:\n\npermissions:\n  contents: read #  to fetch code (actions/checkout)\n\njobs:\n  test:\n    strategy:\n      matrix:\n        node: [14.x, 16.x, 18.x, 20.x, 22.x, 24.x]\n        os: [ubuntu-latest, macos-15-intel, windows-latest]\n    runs-on: ${{ matrix.os }}\n    steps:\n    - uses: actions/checkout@v3\n    - name: Use Node.js ${{ matrix.node }}\n      uses: actions/setup-node@v3\n      with:\n        node-version: ${{ matrix.node }}\n    - run: npm install\n    - run: npm test\n"
  },
  {
    "path": ".gitignore",
    "content": ".nyc_output/\ncoverage/\nnode_modules/\n\n.idea\n*.iml\nnpm-debug.log\n"
  },
  {
    "path": ".npmrc",
    "content": "package-lock=false\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "11.3.4 / 2026-03-03\n-------------------\n\n- Fix bug where calling `ensureSymlink`/`ensureSymlinkSync` with a relative `srcPath` would fail if the symlink already existed ([#1038](https://github.com/jprichardson/node-fs-extra/issues/1038), [#1064](https://github.com/jprichardson/node-fs-extra/pull/1064))\n\n11.3.3 / 2025-12-18\n-------------------\n\n- Fix copying symlink when destination is a symlink to the same target ([#1019](https://github.com/jprichardson/node-fs-extra/issues/1019), [#1060](https://github.com/jprichardson/node-fs-extra/pull/1060))\n\n11.3.2 / 2025-09-15\n-------------------\n\n- Fix spurrious `UnhandledPromiseRejectionWarning` that could occur when calling `.copy()` in some cases ([#1056](https://github.com/jprichardson/node-fs-extra/issues/1056), [#1058](https://github.com/jprichardson/node-fs-extra/pull/1058))\n\n11.3.1 / 2025-08-05\n-------------------\n\n- Fix case where `move`/`moveSync` could incorrectly think files are identical on Windows ([#1050](https://github.com/jprichardson/node-fs-extra/pull/1050))\n\n11.3.0 / 2025-01-15\n-------------------\n\n- Add promise support for newer `fs` methods ([#1044](https://github.com/jprichardson/node-fs-extra/issues/1044), [#1045](https://github.com/jprichardson/node-fs-extra/pull/1045))\n- Use `fs.opendir` in `copy()`/`copySync()` for better perf/scalability ([#972](https://github.com/jprichardson/node-fs-extra/issues/972), [#1028](https://github.com/jprichardson/node-fs-extra/pull/1028))\n\n11.2.0 / 2023-11-27\n-------------------\n\n- Copy directory contents in parallel for better performance ([#1026](https://github.com/jprichardson/node-fs-extra/pull/1026))\n- Refactor internal code to use `async`/`await` ([#1020](https://github.com/jprichardson/node-fs-extra/issues/1020))\n\n11.1.1 / 2023-03-20\n-------------------\n\n- Preserve timestamps when moving files across devices ([#992](https://github.com/jprichardson/node-fs-extra/issues/992), [#994](https://github.com/jprichardson/node-fs-extra/pull/994))\n\n11.1.0 / 2022-11-29\n-------------------\n\n- Re-add `main` field to `package.json` for better TypeScript compatibility ([#979](https://github.com/jprichardson/node-fs-extra/issues/979), [#981](https://github.com/jprichardson/node-fs-extra/pull/981))\n\n11.0.0 / 2022-11-28\n-------------------\n\n### Breaking Changes\n\n- Don't allow requiring `fs-extra/lib/SOMETHING` (switched to `exports`) ([#974](https://github.com/jprichardson/node-fs-extra/pull/974))\n- Require Node v14.14+ ([#968](https://github.com/jprichardson/node-fs-extra/issues/968), [#969](https://github.com/jprichardson/node-fs-extra/pull/969))\n\n### New Features\n\n- Add `fs-extra/esm` for ESM named export support; see [docs](https://github.com/jprichardson/node-fs-extra#esm) for details ([#746](https://github.com/jprichardson/node-fs-extra/issues/746), [#974](https://github.com/jprichardson/node-fs-extra/pull/974))\n- Add promise support for `fs.readv()` ([#970](https://github.com/jprichardson/node-fs-extra/pull/970))\n\n### Bugfixes\n\n- Don't `stat` filtered items in `copy*` ([#965](https://github.com/jprichardson/node-fs-extra/issues/965), [#971](https://github.com/jprichardson/node-fs-extra/pull/971))\n- Remove buggy stats check in `copy` ([#918](https://github.com/jprichardson/node-fs-extra/issues/918), [#976](https://github.com/jprichardson/node-fs-extra/pull/976))\n\n10.1.0 / 2022-04-16\n-------------------\n\n- Warn if `fs.realpath.native` does not exist, instead of erroring ([#953](https://github.com/jprichardson/node-fs-extra/pull/953))\n- Allow explicitly passing `undefined` options to `move()` ([#947](https://github.com/jprichardson/node-fs-extra/issues/947), [#955](https://github.com/jprichardson/node-fs-extra/pull/955))\n- Use `process.emitWarning` instead of `console.warn` ([#954](https://github.com/jprichardson/node-fs-extra/pull/954))\n\n10.0.1 / 2022-02-22\n-------------------\n\n- Add `sideEffects: false` to `package.json` ([#941](https://github.com/jprichardson/node-fs-extra/pull/941))\n\n10.0.0 / 2021-05-03\n-------------------\n\n### Breaking changes\n\n- Require Node.js v12+ ([#886](https://github.com/jprichardson/node-fs-extra/issues/886), [#893](https://github.com/jprichardson/node-fs-extra/pull/893), [#890](https://github.com/jprichardson/node-fs-extra/pull/890), [#894](https://github.com/jprichardson/node-fs-extra/pull/894), [#895]( https://github.com/jprichardson/node-fs-extra/pull/895))\n- Allow copying broken symlinks ([#779](https://github.com/jprichardson/node-fs-extra/pull/779), [#765](https://github.com/jprichardson/node-fs-extra/issues/765), [#638](https://github.com/jprichardson/node-fs-extra/issues/638), [#761](https://github.com/jprichardson/node-fs-extra/issues/761))\n\n**The following changes, although technically semver-major, will not affect the vast majority of users:**\n\n- Ensure correct type when destination exists for `ensureLink*()`/`ensureSymlink*()` ([#826](https://github.com/jprichardson/node-fs-extra/pull/826), [#786](https://github.com/jprichardson/node-fs-extra/issues/786), [#870](https://github.com/jprichardson/node-fs-extra/issues/870))\n- Error when attempting to `copy*()` unknown file type ([#880](https://github.com/jprichardson/node-fs-extra/pull/880))\n- Remove undocumented options for `remove*()` ([#882](https://github.com/jprichardson/node-fs-extra/pull/882))\n\n### Improvements\n\n- Allow changing case of filenames with `move*()`, even on technically case-insensitive filesystems ([#759](https://github.com/jprichardson/node-fs-extra/issues/759), [#801](https://github.com/jprichardson/node-fs-extra/pull/801))\n- Use native `fs.rm*()` for `remove*()` in environments that support it ([#882](https://github.com/jprichardson/node-fs-extra/pull/882), [#806](https://github.com/jprichardson/node-fs-extra/issues/806))\n- Improve `emptyDir()` performance ([#885](https://github.com/jprichardson/node-fs-extra/pull/885))\n\n### Bugfixes\n\n- Ensure `copy*()`'s `filter` function is not called more than necessary ([#883](https://github.com/jprichardson/node-fs-extra/pull/883), [#809](https://github.com/jprichardson/node-fs-extra/issues/809))\n- Fix `move*()` raising `EPERM` error when moving a file to the root of a drive on Windows ([#897](https://github.com/jprichardson/node-fs-extra/pull/897), [#819](https://github.com/jprichardson/node-fs-extra/issues/819))\n\n### Miscellaneous changes\n\n- Do not use `at-least-node` as a dependency ([#896](https://github.com/jprichardson/node-fs-extra/pull/896))\n- Improve documentation ([#888](https://github.com/jprichardson/node-fs-extra/pull/888), [#830](https://github.com/jprichardson/node-fs-extra/issues/830), [#884](https://github.com/jprichardson/node-fs-extra/pull/884), [#843](https://github.com/jprichardson/node-fs-extra/issues/843))\n\n9.1.0 / 2021-01-19\n------------------\n\n- Add promise support for `fs.rm()` ([#841](https://github.com/jprichardson/node-fs-extra/issues/841), [#860](https://github.com/jprichardson/node-fs-extra/pull/860))\n- Upgrade universalify for performance improvments ([#825](https://github.com/jprichardson/node-fs-extra/pull/825))\n\n9.0.1 / 2020-06-03\n------------------\n\n- Fix issue with `ensureFile()` when used with Jest on Windows ([#804](https://github.com/jprichardson/node-fs-extra/issues/804), [#805](https://github.com/jprichardson/node-fs-extra/pull/805))\n- Remove unneeded `process.umask()` call ([#791](https://github.com/jprichardson/node-fs-extra/pull/791))\n- Docs improvements ([#753](https://github.com/jprichardson/node-fs-extra/pull/753), [#795](https://github.com/jprichardson/node-fs-extra/pull/795), [#797](https://github.com/jprichardson/node-fs-extra/pull/797))\n\n9.0.0 / 2020-03-19\n------------------\n\n### Breaking changes\n\n- Requires Node.js version 10 or greater ([#725](https://github.com/jprichardson/node-fs-extra/issues/725), [#751](https://github.com/jprichardson/node-fs-extra/pull/751))\n- Switched `ensureDir*` to use a fork of https://github.com/sindresorhus/make-dir to make use of native recursive `fs.mkdir` where possible ([#619](https://github.com/jprichardson/node-fs-extra/issues/619), [#756](https://github.com/jprichardson/node-fs-extra/pull/756))\n- Properly preserve `atime` for `copy*` with `preserveTimestamps` option ([#633](https://github.com/jprichardson/node-fs-extra/pull/633))\n\n**The following changes, allthough technically breaking, will not affect the vast majority of users:**\n\n- `outputJson` now outputs objects as they were when the function was called, even if they are mutated later ([#702](https://github.com/jprichardson/node-fs-extra/issues/702), [#768](https://github.com/jprichardson/node-fs-extra/pull/768))\n- Cannot pass `null` as an options parameter to `*Json*` methods ([#745](https://github.com/jprichardson/node-fs-extra/issues/745), [#768](https://github.com/jprichardson/node-fs-extra/pull/768))\n\n### Improvements\n\n- Add promise shims for `fs.writev` & `fs.opendir` ([#747](https://github.com/jprichardson/node-fs-extra/pull/747))\n- Better errors for `ensureFile` ([#696](https://github.com/jprichardson/node-fs-extra/issues/696), [#744](https://github.com/jprichardson/node-fs-extra/pull/744))\n- Better file comparison for older Node versions ([#694](https://github.com/jprichardson/node-fs-extra/pull/694))\n\n### Miscellaneous changes\n- Peformance optimizations ([#762](https://github.com/jprichardson/node-fs-extra/issues/762), [#764](https://github.com/jprichardson/node-fs-extra/pull/764))\n- Add missing documentation for aliases ([#758](https://github.com/jprichardson/node-fs-extra/issues/758), [#766](https://github.com/jprichardson/node-fs-extra/pull/766))\n- Update `universalify` dependency ([#767](https://github.com/jprichardson/node-fs-extra/pull/767))\n\n8.1.0 / 2019-06-28\n------------------\n\n- Add support for promisified `fs.realpath.native` in Node v9.2+ ([#650](https://github.com/jprichardson/node-fs-extra/issues/650), [#682](https://github.com/jprichardson/node-fs-extra/pull/682))\n- Update `graceful-fs` dependency ([#700](https://github.com/jprichardson/node-fs-extra/pull/700))\n- Use `graceful-fs` everywhere ([#700](https://github.com/jprichardson/node-fs-extra/pull/700))\n\n8.0.1 / 2019-05-13\n------------------\n\n- Fix bug `Maximum call stack size exceeded` error in `util/stat` ([#679](https://github.com/jprichardson/node-fs-extra/pull/679))\n\n8.0.0 / 2019-05-11\n------------------\n\n**NOTE:** Node.js v6 support is deprecated, and will be dropped in the next major release.\n\n- Use `renameSync()` under the hood in `moveSync()`\n- Fix bug with bind-mounted directories in `copy*()` ([#613](https://github.com/jprichardson/node-fs-extra/issues/613), [#618](https://github.com/jprichardson/node-fs-extra/pull/618))\n- Fix bug in `move()` with case-insensitive file systems\n- Use `fs.stat()`'s `bigint` option in `copy*()` & `move*()` where possible ([#657](https://github.com/jprichardson/node-fs-extra/issues/657))\n\n7.0.1 / 2018-11-07\n------------------\n\n- Fix `removeSync()` on Windows, in some cases, it would error out with `ENOTEMPTY` ([#646](https://github.com/jprichardson/node-fs-extra/pull/646))\n- Document `mode` option for `ensureDir*()` ([#587](https://github.com/jprichardson/node-fs-extra/pull/587))\n- Don't include documentation files in npm package tarball ([#642](https://github.com/jprichardson/node-fs-extra/issues/642), [#643](https://github.com/jprichardson/node-fs-extra/pull/643))\n\n7.0.0 / 2018-07-16\n------------------\n\n- **BREAKING:** Refine `copy*()` handling of symlinks to properly detect symlinks that point to the same file. ([#582](https://github.com/jprichardson/node-fs-extra/pull/582))\n- Fix bug with copying write-protected directories ([#600](https://github.com/jprichardson/node-fs-extra/pull/600))\n- Universalify `fs.lchmod()` ([#596](https://github.com/jprichardson/node-fs-extra/pull/596))\n- Add `engines` field to `package.json` ([#580](https://github.com/jprichardson/node-fs-extra/pull/580))\n\n6.0.1 / 2018-05-09\n------------------\n\n- Fix `fs.promises` `ExperimentalWarning` on Node v10.1.0 ([#578](https://github.com/jprichardson/node-fs-extra/pull/578))\n\n6.0.0 / 2018-05-01\n------------------\n\n- Drop support for Node.js versions 4, 5, & 7 ([#564](https://github.com/jprichardson/node-fs-extra/pull/564))\n- Rewrite `move` to use `fs.rename` where possible ([#549](https://github.com/jprichardson/node-fs-extra/pull/549))\n- Don't convert relative paths to absolute paths for `filter` ([#554](https://github.com/jprichardson/node-fs-extra/pull/554))\n- `copy*`'s behavior when `preserveTimestamps` is `false` has been OS-dependent since 5.0.0, but that's now explicitly noted in the docs ([#563](https://github.com/jprichardson/node-fs-extra/pull/563))\n- Fix subdirectory detection for `copy*` & `move*` ([#541](https://github.com/jprichardson/node-fs-extra/pull/541))\n- Handle case-insensitive paths correctly in `copy*` ([#568](https://github.com/jprichardson/node-fs-extra/pull/568))\n\n5.0.0 / 2017-12-11\n------------------\n\nSignificant refactor of `copy()` & `copySync()`, including breaking changes. No changes to other functions in this release.\n\nHuge thanks to **[@manidlou](https://github.com/manidlou)** for doing most of the work on this release.\n\n- The `filter` option can no longer be a RegExp (must be a function). This was deprecated since fs-extra v1.0.0. [#512](https://github.com/jprichardson/node-fs-extra/pull/512)\n- `copy()`'s `filter` option can now be a function that returns a Promise. [#518](https://github.com/jprichardson/node-fs-extra/pull/518)\n- `copy()` & `copySync()` now use `fs.copyFile()`/`fs.copyFileSync()` in environments that support it (currently Node 8.5.0+). Older Node versions still get the old implementation. [#505](https://github.com/jprichardson/node-fs-extra/pull/505)\n- Don't allow copying a directory into itself. [#83](https://github.com/jprichardson/node-fs-extra/issues/83)\n- Handle copying between identical files. [#198](https://github.com/jprichardson/node-fs-extra/issues/198)\n- Error out when copying an empty folder to a path that already exists. [#464](https://github.com/jprichardson/node-fs-extra/issues/464)\n- Don't create `dest`'s parent if the `filter` function aborts the `copy()` operation. [#517](https://github.com/jprichardson/node-fs-extra/pull/517)\n- Fix `writeStream` not being closed if there was an error in `copy()`. [#516](https://github.com/jprichardson/node-fs-extra/pull/516)\n\n4.0.3 / 2017-12-05\n------------------\n\n- Fix wrong `chmod` values in `fs.remove()` [#501](https://github.com/jprichardson/node-fs-extra/pull/501)\n- Fix `TypeError` on systems that don't have some `fs` operations like `lchown` [#520](https://github.com/jprichardson/node-fs-extra/pull/520)\n\n4.0.2 / 2017-09-12\n------------------\n\n- Added `EOL` option to `writeJson*` & `outputJson*` (via upgrade to jsonfile v4)\n- Added promise support to [`fs.copyFile()`](https://nodejs.org/api/fs.html#fs_fs_copyfile_src_dest_flags_callback) in Node 8.5+\n- Added `.js` extension to `main` field in `package.json` for better tooling compatibility. [#485](https://github.com/jprichardson/node-fs-extra/pull/485)\n\n4.0.1 / 2017-07-31\n------------------\n\n### Fixed\n\n- Previously, `ensureFile()` & `ensureFileSync()` would do nothing if the path was a directory. Now, they error out for consistency with `ensureDir()`. [#465](https://github.com/jprichardson/node-fs-extra/issues/465), [#466](https://github.com/jprichardson/node-fs-extra/pull/466), [#470](https://github.com/jprichardson/node-fs-extra/issues/470)\n\n4.0.0 / 2017-07-14\n------------------\n\n### Changed\n\n- **BREAKING:** The promisified versions of `fs.read()` & `fs.write()` now return objects. See [the docs](docs/fs-read-write.md) for details. [#436](https://github.com/jprichardson/node-fs-extra/issues/436), [#449](https://github.com/jprichardson/node-fs-extra/pull/449)\n- `fs.move()` now errors out when destination is a subdirectory of source. [#458](https://github.com/jprichardson/node-fs-extra/pull/458)\n- Applied upstream fixes from `rimraf` to `fs.remove()` & `fs.removeSync()`. [#459](https://github.com/jprichardson/node-fs-extra/pull/459)\n\n### Fixed\n\n- Got `fs.outputJSONSync()` working again; it was broken due to refactoring. [#428](https://github.com/jprichardson/node-fs-extra/pull/428)\n\nAlso clarified the docs in a few places.\n\n3.0.1 / 2017-05-04\n------------------\n\n- Fix bug in `move()` & `moveSync()` when source and destination are the same, and source does not exist. [#415](https://github.com/jprichardson/node-fs-extra/pull/415)\n\n3.0.0 / 2017-04-27\n------------------\n\n### Added\n\n- **BREAKING:** Added Promise support. All asynchronous native fs methods and fs-extra methods now return a promise if the callback is not passed. [#403](https://github.com/jprichardson/node-fs-extra/pull/403)\n- `pathExists()`, a replacement for the deprecated `fs.exists`. `pathExists` has a normal error-first callback signature. Also added `pathExistsSync`, an alias to `fs.existsSync`, for completeness. [#406](https://github.com/jprichardson/node-fs-extra/pull/406)\n\n### Removed\n\n- **BREAKING:** Removed support for setting the default spaces for `writeJson()`, `writeJsonSync()`, `outputJson()`, & `outputJsonSync()`. This was undocumented. [#402](https://github.com/jprichardson/node-fs-extra/pull/402)\n\n### Changed\n\n- Upgraded jsonfile dependency to v3.0.0:\n  - **BREAKING:** Changed behavior of `throws` option for `readJsonSync()`; now does not throw filesystem errors when `throws` is `false`.\n- **BREAKING:** `writeJson()`, `writeJsonSync()`, `outputJson()`, & `outputJsonSync()` now output minified JSON by default for consistency with `JSON.stringify()`; set the `spaces` option to `2` to override this new behavior. [#402](https://github.com/jprichardson/node-fs-extra/pull/402)\n- Use `Buffer.allocUnsafe()` instead of `new Buffer()` in environments that support it. [#394](https://github.com/jprichardson/node-fs-extra/pull/394)\n\n### Fixed\n\n- `removeSync()` silently failed on Windows in some cases. Now throws an `EBUSY` error. [#408](https://github.com/jprichardson/node-fs-extra/pull/408)\n\n2.1.2 / 2017-03-16\n------------------\n\n### Fixed\n\n- Weird windows bug that resulted in `ensureDir()`'s callback being called twice in some cases. This bug may have also affected `remove()`. See [#392](https://github.com/jprichardson/node-fs-extra/issues/392), [#393](https://github.com/jprichardson/node-fs-extra/pull/393)\n\n2.1.1 / 2017-03-15\n------------------\n\n### Fixed\n\n- Reverted [`5597bd`](https://github.com/jprichardson/node-fs-extra/commit/5597bd5b67f7d060f5f5bf26e9635be48330f5d7), this broke compatibility with Node.js versions v4+ but less than `v4.5.0`.\n- Remove `Buffer.alloc()` usage in `moveSync()`.\n\n2.1.0 / 2017-03-15\n------------------\n\nThanks to [Mani Maghsoudlou (@manidlou)](https://github.com/manidlou) & [Jan Peer Stöcklmair (@JPeer264)](https://github.com/JPeer264) for their extraordinary help with this release!\n\n### Added\n- `moveSync()` See [#309], [#381](https://github.com/jprichardson/node-fs-extra/pull/381). ([@manidlou](https://github.com/manidlou))\n- `copy()` and `copySync()`'s `filter` option now gets the destination path passed as the second parameter. [#366](https://github.com/jprichardson/node-fs-extra/pull/366) ([@manidlou](https://github.com/manidlou))\n\n### Changed\n- Use `Buffer.alloc()` instead of deprecated `new Buffer()` in `copySync()`. [#380](https://github.com/jprichardson/node-fs-extra/pull/380) ([@manidlou](https://github.com/manidlou))\n- Refactored entire codebase to use ES6 features supported by Node.js v4+ [#355](https://github.com/jprichardson/node-fs-extra/issues/355). [(@JPeer264)](https://github.com/JPeer264)\n- Refactored docs. ([@manidlou](https://github.com/manidlou))\n\n### Fixed\n\n- `move()` shouldn't error out when source and dest are the same. [#377](https://github.com/jprichardson/node-fs-extra/issues/377), [#378](https://github.com/jprichardson/node-fs-extra/pull/378) ([@jdalton](https://github.com/jdalton))\n\n2.0.0 / 2017-01-16\n------------------\n\n### Removed\n- **BREAKING:** Removed support for Node `v0.12`. The Node foundation stopped officially supporting it\non Jan 1st, 2017.\n- **BREAKING:** Remove `walk()` and `walkSync()`. `walkSync()` was only part of `fs-extra` for a little\nover two months. Use [klaw](https://github.com/jprichardson/node-klaw) instead of `walk()`, in fact, `walk()` was just\nan alias to klaw. For `walkSync()` use [klaw-sync](https://github.com/mawni/node-klaw-sync). See: [#338], [#339]\n\n### Changed\n- **BREAKING:** Renamed `clobber` to `overwrite`. This affects `copy()`, `copySync()`, and `move()`. [#330], [#333]\n- Moved docs, to `docs/`. [#340]\n\n### Fixed\n- Apply filters to directories in `copySync()` like in `copy()`. [#324]\n- A specific condition when disk is under heavy use, `copy()` can fail. [#326]\n\n\n1.0.0 / 2016-11-01\n------------------\n\nAfter five years of development, we finally have reach the 1.0.0 milestone! Big thanks goes\nto [Ryan Zim](https://github.com/RyanZim) for leading the charge on this release!\n\n### Added\n- `walkSync()`\n\n### Changed\n- **BREAKING**: dropped Node v0.10 support.\n- disabled `rimaf` globbing, wasn't used. [#280]\n- deprecate `copy()/copySync()` option `filter` if it's a `RegExp`. `filter` should now be a function.\n- inline `rimraf`. This is temporary and was done because `rimraf` depended upon the beefy `glob` which `fs-extra` does not use. [#300]\n\n### Fixed\n- bug fix proper closing of file handle on `utimesMillis()` [#271]\n- proper escaping of files with dollar signs [#291]\n- `copySync()` failed if user didn't own file. [#199], [#301]\n\n\n0.30.0 / 2016-04-28\n-------------------\n- Brought back Node v0.10 support. I didn't realize there was still demand. Official support will end **2016-10-01**.\n\n0.29.0 / 2016-04-27\n-------------------\n- **BREAKING**: removed support for Node v0.10. If you still want to use Node v0.10, everything should work except for `ensureLink()/ensureSymlink()`. Node v0.12 is still supported but will be dropped in the near future as well.\n\n0.28.0 / 2016-04-17\n-------------------\n- **BREAKING**: removed `createOutputStream()`. Use https://www.npmjs.com/package/create-output-stream. See: [#192][#192]\n- `mkdirs()/mkdirsSync()` check for invalid win32 path chars. See: [#209][#209], [#237][#237]\n- `mkdirs()/mkdirsSync()` if drive not mounted, error. See: [#93][#93]\n\n0.27.0 / 2016-04-15\n-------------------\n- add `dereference` option to `copySync()`. [#235][#235]\n\n0.26.7 / 2016-03-16\n-------------------\n- fixed `copy()` if source and dest are the same. [#230][#230]\n\n0.26.6 / 2016-03-15\n-------------------\n- fixed if `emptyDir()` does not have a callback: [#229][#229]\n\n0.26.5 / 2016-01-27\n-------------------\n- `copy()` with two arguments (w/o callback) was broken. See: [#215][#215]\n\n0.26.4 / 2016-01-05\n-------------------\n- `copySync()` made `preserveTimestamps` default consistent with `copy()` which is `false`. See: [#208][#208]\n\n0.26.3 / 2015-12-17\n-------------------\n- fixed `copy()` hangup in copying blockDevice / characterDevice / `/dev/null`. See: [#193][#193]\n\n0.26.2 / 2015-11-02\n-------------------\n- fixed `outputJson{Sync}()` spacing adherence to `fs.spaces`\n\n0.26.1 / 2015-11-02\n-------------------\n- fixed `copySync()` when `clogger=true` and the destination is read only. See: [#190][#190]\n\n0.26.0 / 2015-10-25\n-------------------\n- extracted the `walk()` function into its own module [`klaw`](https://github.com/jprichardson/node-klaw).\n\n0.25.0 / 2015-10-24\n-------------------\n- now has a file walker `walk()`\n\n0.24.0 / 2015-08-28\n-------------------\n- removed alias `delete()` and `deleteSync()`. See: [#171][#171]\n\n0.23.1 / 2015-08-07\n-------------------\n- Better handling of errors for `move()` when moving across devices. [#170][#170]\n- `ensureSymlink()` and `ensureLink()` should not throw errors if link exists. [#169][#169]\n\n0.23.0 / 2015-08-06\n-------------------\n- added `ensureLink{Sync}()` and `ensureSymlink{Sync}()`. See: [#165][#165]\n\n0.22.1 / 2015-07-09\n-------------------\n- Prevent calling `hasMillisResSync()` on module load. See: [#149][#149].\nFixes regression that was introduced in `0.21.0`.\n\n0.22.0 / 2015-07-09\n-------------------\n- preserve permissions / ownership in `copy()`. See: [#54][#54]\n\n0.21.0 / 2015-07-04\n-------------------\n- add option to preserve timestamps in `copy()` and `copySync()`. See: [#141][#141]\n- updated `graceful-fs@3.x` to `4.x`. This brings in features from `amazing-graceful-fs` (much cleaner code / less hacks)\n\n0.20.1 / 2015-06-23\n-------------------\n- fixed regression caused by latest jsonfile update: See: https://github.com/jprichardson/node-jsonfile/issues/26\n\n0.20.0 / 2015-06-19\n-------------------\n- removed `jsonfile` aliases with `File` in the name, they weren't documented and probably weren't in use e.g.\nthis package had both `fs.readJsonFile` and `fs.readJson` that were aliases to each other, now use `fs.readJson`.\n- preliminary walker created. Intentionally not documented. If you use it, it will almost certainly change and break your code.\n- started moving tests inline\n- upgraded to `jsonfile@2.1.0`, can now pass JSON revivers/replacers to `readJson()`, `writeJson()`, `outputJson()`\n\n0.19.0 / 2015-06-08\n-------------------\n- `fs.copy()` had support for Node v0.8, dropped support\n\n0.18.4 / 2015-05-22\n-------------------\n- fixed license field according to this: [#136][#136] and https://github.com/npm/npm/releases/tag/v2.10.0\n\n0.18.3 / 2015-05-08\n-------------------\n- bugfix: handle `EEXIST` when clobbering on some Linux systems. [#134][#134]\n\n0.18.2 / 2015-04-17\n-------------------\n- bugfix: allow `F_OK` ([#120][#120])\n\n0.18.1 / 2015-04-15\n-------------------\n- improved windows support for `move()` a bit. https://github.com/jprichardson/node-fs-extra/commit/92838980f25dc2ee4ec46b43ee14d3c4a1d30c1b\n- fixed a lot of tests for Windows (appveyor)\n\n0.18.0 / 2015-03-31\n-------------------\n- added `emptyDir()` and `emptyDirSync()`\n\n0.17.0 / 2015-03-28\n-------------------\n- `copySync` added `clobber` option (before always would clobber, now if `clobber` is `false` it throws an error if the destination exists).\n**Only works with files at the moment.**\n- `createOutputStream()` added. See: [#118][#118]\n\n0.16.5 / 2015-03-08\n-------------------\n- fixed `fs.move` when `clobber` is `true` and destination is a directory, it should clobber. [#114][#114]\n\n0.16.4 / 2015-03-01\n-------------------\n- `fs.mkdirs` fix infinite loop on Windows. See: See https://github.com/substack/node-mkdirp/pull/74 and https://github.com/substack/node-mkdirp/issues/66\n\n0.16.3 / 2015-01-28\n-------------------\n- reverted https://github.com/jprichardson/node-fs-extra/commit/1ee77c8a805eba5b99382a2591ff99667847c9c9\n\n\n0.16.2 / 2015-01-28\n-------------------\n- fixed `fs.copy` for Node v0.8 (support is temporary and will be removed in the near future)\n\n0.16.1 / 2015-01-28\n-------------------\n- if `setImmediate` is not available, fall back to `process.nextTick`\n\n0.16.0 / 2015-01-28\n-------------------\n- bugfix `fs.move()` into itself. Closes [#104]\n- bugfix `fs.move()` moving directory across device. Closes [#108]\n- added coveralls support\n- bugfix: nasty multiple callback `fs.copy()` bug. Closes [#98]\n- misc fs.copy code cleanups\n\n0.15.0 / 2015-01-21\n-------------------\n- dropped `ncp`, imported code in\n- because of previous, now supports `io.js`\n- `graceful-fs` is now a dependency\n\n0.14.0 / 2015-01-05\n-------------------\n- changed `copy`/`copySync` from `fs.copy(src, dest, [filters], callback)` to `fs.copy(src, dest, [options], callback)` [#100][#100]\n- removed mockfs tests for mkdirp (this may be temporary, but was getting in the way of other tests)\n\n0.13.0 / 2014-12-10\n-------------------\n- removed `touch` and `touchSync` methods (they didn't handle permissions like UNIX touch)\n- updated `\"ncp\": \"^0.6.0\"` to `\"ncp\": \"^1.0.1\"`\n- imported `mkdirp` => `minimist` and `mkdirp` are no longer dependences, should now appease people who wanted `mkdirp` to be `--use_strict` safe. See [#59]([#59][#59])\n\n0.12.0 / 2014-09-22\n-------------------\n- copy symlinks in `copySync()` [#85][#85]\n\n0.11.1 / 2014-09-02\n-------------------\n- bugfix `copySync()` preserve file permissions [#80][#80]\n\n0.11.0 / 2014-08-11\n-------------------\n- upgraded `\"ncp\": \"^0.5.1\"` to `\"ncp\": \"^0.6.0\"`\n- upgrade `jsonfile\": \"^1.2.0\"` to `jsonfile\": \"^2.0.0\"` => on write, json files now have `\\n` at end. Also adds `options.throws` to `readJsonSync()`\nsee https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options for more details.\n\n0.10.0 / 2014-06-29\n------------------\n* bugfix: upgaded `\"jsonfile\": \"~1.1.0\"` to `\"jsonfile\": \"^1.2.0\"`, bumped minor because of `jsonfile` dep change\nfrom `~` to `^`. [#67]\n\n0.9.1 / 2014-05-22\n------------------\n* removed Node.js `0.8.x` support, `0.9.0` was published moments ago and should have been done there\n\n0.9.0 / 2014-05-22\n------------------\n* upgraded `ncp` from `~0.4.2` to `^0.5.1`, [#58]\n* upgraded `rimraf` from `~2.2.6` to `^2.2.8`\n* upgraded `mkdirp` from `0.3.x` to `^0.5.0`\n* added methods `ensureFile()`, `ensureFileSync()`\n* added methods `ensureDir()`, `ensureDirSync()` [#31]\n* added `move()` method. From: https://github.com/andrewrk/node-mv\n\n\n0.8.1 / 2013-10-24\n------------------\n* copy failed to return an error to the callback if a file doesn't exist (ulikoehler [#38], [#39])\n\n0.8.0 / 2013-10-14\n------------------\n* `filter` implemented on `copy()` and `copySync()`. (Srirangan / [#36])\n\n0.7.1 / 2013-10-12\n------------------\n* `copySync()` implemented (Srirangan / [#33])\n* updated to the latest `jsonfile` version `1.1.0` which gives `options` params for the JSON methods. Closes [#32]\n\n0.7.0 / 2013-10-07\n------------------\n* update readme conventions\n* `copy()` now works if destination directory does not exist. Closes [#29]\n\n0.6.4 / 2013-09-05\n------------------\n* changed `homepage` field in package.json to remove NPM warning\n\n0.6.3 / 2013-06-28\n------------------\n* changed JSON spacing default from `4` to `2` to follow Node conventions\n* updated `jsonfile` dep\n* updated `rimraf` dep\n\n0.6.2 / 2013-06-28\n------------------\n* added .npmignore, [#25]\n\n0.6.1 / 2013-05-14\n------------------\n* modified for `strict` mode, closes [#24]\n* added `outputJson()/outputJsonSync()`, closes [#23]\n\n0.6.0 / 2013-03-18\n------------------\n* removed node 0.6 support\n* added node 0.10 support\n* upgraded to latest `ncp` and `rimraf`.\n* optional `graceful-fs` support. Closes [#17]\n\n\n0.5.0 / 2013-02-03\n------------------\n* Removed `readTextFile`.\n* Renamed `readJSONFile` to `readJSON` and `readJson`, same with write.\n* Restructured documentation a bit. Added roadmap.\n\n0.4.0 / 2013-01-28\n------------------\n* Set default spaces in `jsonfile` from 4 to 2.\n* Updated `testutil` deps for tests.\n* Renamed `touch()` to `createFile()`\n* Added `outputFile()` and `outputFileSync()`\n* Changed creation of testing diretories so the /tmp dir is not littered.\n* Added `readTextFile()` and `readTextFileSync()`.\n\n0.3.2 / 2012-11-01\n------------------\n* Added `touch()` and `touchSync()` methods.\n\n0.3.1 / 2012-10-11\n------------------\n* Fixed some stray globals.\n\n0.3.0 / 2012-10-09\n------------------\n* Removed all CoffeeScript from tests.\n* Renamed `mkdir` to `mkdirs`/`mkdirp`.\n\n0.2.1 / 2012-09-11\n------------------\n* Updated `rimraf` dep.\n\n0.2.0 / 2012-09-10\n------------------\n* Rewrote module into JavaScript. (Must still rewrite tests into JavaScript)\n* Added all methods of [jsonfile](https://github.com/jprichardson/node-jsonfile)\n* Added Travis-CI.\n\n0.1.3 / 2012-08-13\n------------------\n* Added method `readJSONFile`.\n\n0.1.2 / 2012-06-15\n------------------\n* Bug fix: `deleteSync()` didn't exist.\n* Verified Node v0.8 compatibility.\n\n0.1.1 / 2012-06-15\n------------------\n* Fixed bug in `remove()`/`delete()` that wouldn't execute the function if a callback wasn't passed.\n\n0.1.0 / 2012-05-31\n------------------\n* Renamed `copyFile()` to `copy()`. `copy()` can now copy directories (recursively) too.\n* Renamed `rmrf()` to `remove()`.\n* `remove()` aliased with `delete()`.\n* Added `mkdirp` capabilities. Named: `mkdir()`. Hides Node.js native `mkdir()`.\n* Instead of exporting the native `fs` module with new functions, I now copy over the native methods to a new object and export that instead.\n\n0.0.4 / 2012-03-14\n------------------\n* Removed CoffeeScript dependency\n\n0.0.3 / 2012-01-11\n------------------\n* Added methods rmrf and rmrfSync\n* Moved tests from Jasmine to Mocha\n\n\n[#344]: https://github.com/jprichardson/node-fs-extra/issues/344    \"Licence Year\"\n[#343]: https://github.com/jprichardson/node-fs-extra/pull/343      \"Add klaw-sync link to readme\"\n[#342]: https://github.com/jprichardson/node-fs-extra/pull/342      \"allow preserveTimestamps when use move\"\n[#341]: https://github.com/jprichardson/node-fs-extra/issues/341    \"mkdirp(path.dirname(dest) in move() logic needs cleaning up [question]\"\n[#340]: https://github.com/jprichardson/node-fs-extra/pull/340      \"Move docs to seperate docs folder [documentation]\"\n[#339]: https://github.com/jprichardson/node-fs-extra/pull/339      \"Remove walk() & walkSync() [feature-walk]\"\n[#338]: https://github.com/jprichardson/node-fs-extra/issues/338    \"Remove walk() and walkSync() [feature-walk]\"\n[#337]: https://github.com/jprichardson/node-fs-extra/issues/337    \"copy doesn't return a yieldable value\"\n[#336]: https://github.com/jprichardson/node-fs-extra/pull/336      \"Docs enhanced walk sync [documentation, feature-walk]\"\n[#335]: https://github.com/jprichardson/node-fs-extra/pull/335      \"Refactor move() tests [feature-move]\"\n[#334]: https://github.com/jprichardson/node-fs-extra/pull/334      \"Cleanup lib/move/index.js [feature-move]\"\n[#333]: https://github.com/jprichardson/node-fs-extra/pull/333      \"Rename clobber to overwrite [feature-copy, feature-move]\"\n[#332]: https://github.com/jprichardson/node-fs-extra/pull/332      \"BREAKING: Drop Node v0.12 & io.js support\"\n[#331]: https://github.com/jprichardson/node-fs-extra/issues/331    \"Add support for chmodr [enhancement, future]\"\n[#330]: https://github.com/jprichardson/node-fs-extra/pull/330      \"BREAKING: Do not error when copy destination exists & clobber: false [feature-copy]\"\n[#329]: https://github.com/jprichardson/node-fs-extra/issues/329    \"Does .walk() scale to large directories? [question]\"\n[#328]: https://github.com/jprichardson/node-fs-extra/issues/328    \"Copying files corrupts [feature-copy, needs-confirmed]\"\n[#327]: https://github.com/jprichardson/node-fs-extra/pull/327      \"Use writeStream 'finish' event instead of 'close' [bug, feature-copy]\"\n[#326]: https://github.com/jprichardson/node-fs-extra/issues/326    \"fs.copy fails with chmod error when disk under heavy use [bug, feature-copy]\"\n[#325]: https://github.com/jprichardson/node-fs-extra/issues/325    \"ensureDir is difficult to promisify [enhancement]\"\n[#324]: https://github.com/jprichardson/node-fs-extra/pull/324      \"copySync() should apply filter to directories like copy() [bug, feature-copy]\"\n[#323]: https://github.com/jprichardson/node-fs-extra/issues/323    \"Support for `dest` being a directory when using `copy*()`?\"\n[#322]: https://github.com/jprichardson/node-fs-extra/pull/322      \"Add fs-promise as fs-extra-promise alternative\"\n[#321]: https://github.com/jprichardson/node-fs-extra/issues/321    \"fs.copy() with clobber set to false return EEXIST error [feature-copy]\"\n[#320]: https://github.com/jprichardson/node-fs-extra/issues/320    \"fs.copySync: Error: EPERM: operation not permitted, unlink \"\n[#319]: https://github.com/jprichardson/node-fs-extra/issues/319    \"Create directory if not exists\"\n[#318]: https://github.com/jprichardson/node-fs-extra/issues/318    \"Support glob patterns [enhancement, future]\"\n[#317]: https://github.com/jprichardson/node-fs-extra/pull/317      \"Adding copy sync test for src file without write perms\"\n[#316]: https://github.com/jprichardson/node-fs-extra/pull/316      \"Remove move()'s broken limit option [feature-move]\"\n[#315]: https://github.com/jprichardson/node-fs-extra/pull/315      \"Fix move clobber tests to work around graceful-fs bug.\"\n[#314]: https://github.com/jprichardson/node-fs-extra/issues/314    \"move() limit option [documentation, enhancement, feature-move]\"\n[#313]: https://github.com/jprichardson/node-fs-extra/pull/313      \"Test that remove() ignores glob characters.\"\n[#312]: https://github.com/jprichardson/node-fs-extra/pull/312      \"Enhance walkSync() to return items with path and stats [feature-walk]\"\n[#311]: https://github.com/jprichardson/node-fs-extra/issues/311    \"move() not work when dest name not provided [feature-move]\"\n[#310]: https://github.com/jprichardson/node-fs-extra/issues/310    \"Edit walkSync to return items like what walk emits [documentation, enhancement, feature-walk]\"\n[#309]: https://github.com/jprichardson/node-fs-extra/issues/309    \"moveSync support [enhancement, feature-move]\"\n[#308]: https://github.com/jprichardson/node-fs-extra/pull/308      \"Fix incorrect anchor link\"\n[#307]: https://github.com/jprichardson/node-fs-extra/pull/307      \"Fix coverage\"\n[#306]: https://github.com/jprichardson/node-fs-extra/pull/306      \"Update devDeps, fix lint error\"\n[#305]: https://github.com/jprichardson/node-fs-extra/pull/305      \"Re-add Coveralls\"\n[#304]: https://github.com/jprichardson/node-fs-extra/pull/304      \"Remove path-is-absolute [enhancement]\"\n[#303]: https://github.com/jprichardson/node-fs-extra/pull/303      \"Document copySync filter inconsistency [documentation, feature-copy]\"\n[#302]: https://github.com/jprichardson/node-fs-extra/pull/302      \"fix(console): depreciated -> deprecated\"\n[#301]: https://github.com/jprichardson/node-fs-extra/pull/301      \"Remove chmod call from copySync [feature-copy]\"\n[#300]: https://github.com/jprichardson/node-fs-extra/pull/300      \"Inline Rimraf [enhancement, feature-move, feature-remove]\"\n[#299]: https://github.com/jprichardson/node-fs-extra/pull/299      \"Warn when filter is a RegExp [feature-copy]\"\n[#298]: https://github.com/jprichardson/node-fs-extra/issues/298    \"API Docs [documentation]\"\n[#297]: https://github.com/jprichardson/node-fs-extra/pull/297      \"Warn about using preserveTimestamps on 32-bit node\"\n[#296]: https://github.com/jprichardson/node-fs-extra/pull/296      \"Improve EEXIST error message for copySync [enhancement]\"\n[#295]: https://github.com/jprichardson/node-fs-extra/pull/295      \"Depreciate using regular expressions for copy's filter option [documentation]\"\n[#294]: https://github.com/jprichardson/node-fs-extra/pull/294      \"BREAKING: Refactor lib/copy/ncp.js [feature-copy]\"\n[#293]: https://github.com/jprichardson/node-fs-extra/pull/293      \"Update CI configs\"\n[#292]: https://github.com/jprichardson/node-fs-extra/issues/292    \"Rewrite lib/copy/ncp.js [enhancement, feature-copy]\"\n[#291]: https://github.com/jprichardson/node-fs-extra/pull/291      \"Escape '$' in replacement string for async file copying\"\n[#290]: https://github.com/jprichardson/node-fs-extra/issues/290    \"Exclude files pattern while copying using copy.config.js [question]\"\n[#289]: https://github.com/jprichardson/node-fs-extra/pull/289      \"(Closes #271) lib/util/utimes: properly close file descriptors in the event of an error\"\n[#288]: https://github.com/jprichardson/node-fs-extra/pull/288      \"(Closes #271) lib/util/utimes: properly close file descriptors in the event of an error\"\n[#287]: https://github.com/jprichardson/node-fs-extra/issues/287    \"emptyDir() callback arguments are inconsistent [enhancement, feature-remove]\"\n[#286]: https://github.com/jprichardson/node-fs-extra/pull/286      \"Added walkSync function\"\n[#285]: https://github.com/jprichardson/node-fs-extra/issues/285    \"CITGM test failing on s390\"\n[#284]: https://github.com/jprichardson/node-fs-extra/issues/284    \"outputFile method is missing a check to determine if existing item is a folder or not\"\n[#283]: https://github.com/jprichardson/node-fs-extra/pull/283      \"Apply filter also on directories and symlinks for copySync()\"\n[#282]: https://github.com/jprichardson/node-fs-extra/pull/282      \"Apply filter also on directories and symlinks for copySync()\"\n[#281]: https://github.com/jprichardson/node-fs-extra/issues/281    \"remove function executes 'successfully' but doesn't do anything?\"\n[#280]: https://github.com/jprichardson/node-fs-extra/pull/280      \"Disable rimraf globbing\"\n[#279]: https://github.com/jprichardson/node-fs-extra/issues/279    \"Some code is vendored instead of included [awaiting-reply]\"\n[#278]: https://github.com/jprichardson/node-fs-extra/issues/278    \"copy() does not preserve file/directory ownership\"\n[#277]: https://github.com/jprichardson/node-fs-extra/pull/277      \"Mention defaults for clobber and dereference options\"\n[#276]: https://github.com/jprichardson/node-fs-extra/issues/276    \"Cannot connect to Shared Folder [awaiting-reply]\"\n[#275]: https://github.com/jprichardson/node-fs-extra/issues/275    \"EMFILE, too many open files on Mac OS with JSON API\"\n[#274]: https://github.com/jprichardson/node-fs-extra/issues/274    \"Use with memory-fs? [enhancement, future]\"\n[#273]: https://github.com/jprichardson/node-fs-extra/pull/273      \"tests: rename `remote.test.js` to `remove.test.js`\"\n[#272]: https://github.com/jprichardson/node-fs-extra/issues/272    \"Copy clobber flag never err even when true [bug, feature-copy]\"\n[#271]: https://github.com/jprichardson/node-fs-extra/issues/271    \"Unclosed file handle on futimes error\"\n[#270]: https://github.com/jprichardson/node-fs-extra/issues/270    \"copy not working as desired on Windows [feature-copy, platform-windows]\"\n[#269]: https://github.com/jprichardson/node-fs-extra/issues/269    \"Copying with preserveTimeStamps: true is inaccurate using 32bit node [feature-copy]\"\n[#268]: https://github.com/jprichardson/node-fs-extra/pull/268      \"port fix for mkdirp issue #111\"\n[#267]: https://github.com/jprichardson/node-fs-extra/issues/267    \"WARN deprecated wrench@1.5.9: wrench.js is deprecated!\"\n[#266]: https://github.com/jprichardson/node-fs-extra/issues/266    \"fs-extra\"\n[#265]: https://github.com/jprichardson/node-fs-extra/issues/265    \"Link the `fs.stat fs.exists` etc. methods for replace the `fs` module forever?\"\n[#264]: https://github.com/jprichardson/node-fs-extra/issues/264    \"Renaming a file using move fails when a file inside is open (at least on windows) [wont-fix]\"\n[#263]: https://github.com/jprichardson/node-fs-extra/issues/263    \"ENOSYS: function not implemented, link [needs-confirmed]\"\n[#262]: https://github.com/jprichardson/node-fs-extra/issues/262    \"Add .exists() and .existsSync()\"\n[#261]: https://github.com/jprichardson/node-fs-extra/issues/261    \"Cannot read property 'prototype' of undefined\"\n[#260]: https://github.com/jprichardson/node-fs-extra/pull/260      \"use more specific path for method require\"\n[#259]: https://github.com/jprichardson/node-fs-extra/issues/259    \"Feature Request: isEmpty\"\n[#258]: https://github.com/jprichardson/node-fs-extra/issues/258    \"copy files does not preserve file timestamp\"\n[#257]: https://github.com/jprichardson/node-fs-extra/issues/257    \"Copying a file on windows fails\"\n[#256]: https://github.com/jprichardson/node-fs-extra/pull/256      \"Updated Readme \"\n[#255]: https://github.com/jprichardson/node-fs-extra/issues/255    \"Update rimraf required version\"\n[#254]: https://github.com/jprichardson/node-fs-extra/issues/254    \"request for readTree, readTreeSync, walkSync method\"\n[#253]: https://github.com/jprichardson/node-fs-extra/issues/253    \"outputFile does not touch mtime when file exists\"\n[#252]: https://github.com/jprichardson/node-fs-extra/pull/252      \"Fixing problem when copying file with no write permission\"\n[#251]: https://github.com/jprichardson/node-fs-extra/issues/251    \"Just wanted to say thank you\"\n[#250]: https://github.com/jprichardson/node-fs-extra/issues/250    \"`fs.remove()` not removing files (works with `rm -rf`)\"\n[#249]: https://github.com/jprichardson/node-fs-extra/issues/249    \"Just a Question ... Remove Servers\"\n[#248]: https://github.com/jprichardson/node-fs-extra/issues/248    \"Allow option to not preserve permissions for copy\"\n[#247]: https://github.com/jprichardson/node-fs-extra/issues/247    \"Add TypeScript typing directly in the fs-extra package\"\n[#246]: https://github.com/jprichardson/node-fs-extra/issues/246    \"fse.remove() && fse.removeSync() don't throw error on ENOENT file\"\n[#245]: https://github.com/jprichardson/node-fs-extra/issues/245    \"filter for empty dir [enhancement]\"\n[#244]: https://github.com/jprichardson/node-fs-extra/issues/244    \"copySync doesn't apply the filter to directories\"\n[#243]: https://github.com/jprichardson/node-fs-extra/issues/243    \"Can I request fs.walk() to be synchronous?\"\n[#242]: https://github.com/jprichardson/node-fs-extra/issues/242    \"Accidentally truncates file names ending with $$ [bug, feature-copy]\"\n[#241]: https://github.com/jprichardson/node-fs-extra/pull/241      \"Remove link to createOutputStream\"\n[#240]: https://github.com/jprichardson/node-fs-extra/issues/240    \"walkSync request\"\n[#239]: https://github.com/jprichardson/node-fs-extra/issues/239    \"Depreciate regular expressions for copy's filter [documentation, feature-copy]\"\n[#238]: https://github.com/jprichardson/node-fs-extra/issues/238    \"Can't write to files while in a worker thread.\"\n[#237]: https://github.com/jprichardson/node-fs-extra/issues/237    \".ensureDir(..) fails silently when passed an invalid path...\"\n[#236]: https://github.com/jprichardson/node-fs-extra/issues/236    \"[Removed] Filed under wrong repo\"\n[#235]: https://github.com/jprichardson/node-fs-extra/pull/235      \"Adds symlink dereference option to `fse.copySync` (#191)\"\n[#234]: https://github.com/jprichardson/node-fs-extra/issues/234    \"ensureDirSync fails silent when EACCES: permission denied on travis-ci\"\n[#233]: https://github.com/jprichardson/node-fs-extra/issues/233    \"please make sure the first argument in callback is error object [feature-copy]\"\n[#232]: https://github.com/jprichardson/node-fs-extra/issues/232    \"Copy a folder content  to its child folder.  \"\n[#231]: https://github.com/jprichardson/node-fs-extra/issues/231    \"Adding read/write/output functions for YAML\"\n[#230]: https://github.com/jprichardson/node-fs-extra/pull/230      \"throw error if src and dest are the same to avoid zeroing out + test\"\n[#229]: https://github.com/jprichardson/node-fs-extra/pull/229      \"fix 'TypeError: callback is not a function' in emptyDir\"\n[#228]: https://github.com/jprichardson/node-fs-extra/pull/228      \"Throw error when target is empty so file is not accidentally zeroed out\"\n[#227]: https://github.com/jprichardson/node-fs-extra/issues/227    \"Uncatchable errors when there are invalid arguments [feature-move]\"\n[#226]: https://github.com/jprichardson/node-fs-extra/issues/226    \"Moving to the current directory\"\n[#225]: https://github.com/jprichardson/node-fs-extra/issues/225    \"EBUSY: resource busy or locked, unlink\"\n[#224]: https://github.com/jprichardson/node-fs-extra/issues/224    \"fse.copy ENOENT error\"\n[#223]: https://github.com/jprichardson/node-fs-extra/issues/223    \"Suspicious behavior of fs.existsSync\"\n[#222]: https://github.com/jprichardson/node-fs-extra/pull/222      \"A clearer description of emtpyDir function\"\n[#221]: https://github.com/jprichardson/node-fs-extra/pull/221      \"Update README.md\"\n[#220]: https://github.com/jprichardson/node-fs-extra/pull/220      \"Non-breaking feature: add option 'passStats' to copy methods.\"\n[#219]: https://github.com/jprichardson/node-fs-extra/pull/219      \"Add closing parenthesis in copySync example\"\n[#218]: https://github.com/jprichardson/node-fs-extra/pull/218      \"fix #187 #70 options.filter bug\"\n[#217]: https://github.com/jprichardson/node-fs-extra/pull/217      \"fix #187 #70 options.filter bug\"\n[#216]: https://github.com/jprichardson/node-fs-extra/pull/216      \"fix #187 #70 options.filter bug\"\n[#215]: https://github.com/jprichardson/node-fs-extra/pull/215      \"fse.copy throws error when only src and dest provided [bug, documentation, feature-copy]\"\n[#214]: https://github.com/jprichardson/node-fs-extra/pull/214      \"Fixing copySync anchor tag\"\n[#213]: https://github.com/jprichardson/node-fs-extra/issues/213    \"Merge extfs with this repo\"\n[#212]: https://github.com/jprichardson/node-fs-extra/pull/212      \"Update year to 2016 in README.md and LICENSE\"\n[#211]: https://github.com/jprichardson/node-fs-extra/issues/211    \"Not copying all files\"\n[#210]: https://github.com/jprichardson/node-fs-extra/issues/210    \"copy/copySync behave differently when copying a symbolic file [bug, documentation, feature-copy]\"\n[#209]: https://github.com/jprichardson/node-fs-extra/issues/209    \"In Windows invalid directory name causes infinite loop in ensureDir(). [bug]\"\n[#208]: https://github.com/jprichardson/node-fs-extra/pull/208      \"fix options.preserveTimestamps to false in copy-sync by default [feature-copy]\"\n[#207]: https://github.com/jprichardson/node-fs-extra/issues/207    \"Add `compare` suite of functions\"\n[#206]: https://github.com/jprichardson/node-fs-extra/issues/206    \"outputFileSync\"\n[#205]: https://github.com/jprichardson/node-fs-extra/issues/205    \"fix documents about copy/copySync [documentation, feature-copy]\"\n[#204]: https://github.com/jprichardson/node-fs-extra/pull/204      \"allow copy of block and character device files\"\n[#203]: https://github.com/jprichardson/node-fs-extra/issues/203    \"copy method's argument options couldn't be undefined [bug, feature-copy]\"\n[#202]: https://github.com/jprichardson/node-fs-extra/issues/202    \"why there is not a walkSync method?\"\n[#201]: https://github.com/jprichardson/node-fs-extra/issues/201    \"clobber for directories [feature-copy, future]\"\n[#200]: https://github.com/jprichardson/node-fs-extra/issues/200    \"'copySync' doesn't work in sync\"\n[#199]: https://github.com/jprichardson/node-fs-extra/issues/199    \"fs.copySync fails if user does not own file [bug, feature-copy]\"\n[#198]: https://github.com/jprichardson/node-fs-extra/issues/198    \"handle copying between identical files [feature-copy]\"\n[#197]: https://github.com/jprichardson/node-fs-extra/issues/197    \"Missing documentation for `outputFile` `options` 3rd parameter [documentation]\"\n[#196]: https://github.com/jprichardson/node-fs-extra/issues/196    \"copy filter: async function and/or function called with `fs.stat` result [future]\"\n[#195]: https://github.com/jprichardson/node-fs-extra/issues/195    \"How to override with outputFile?\"\n[#194]: https://github.com/jprichardson/node-fs-extra/pull/194      \"allow ensureFile(Sync) to provide data to be written to created file\"\n[#193]: https://github.com/jprichardson/node-fs-extra/issues/193    \"`fs.copy` fails silently if source file is /dev/null [bug, feature-copy]\"\n[#192]: https://github.com/jprichardson/node-fs-extra/issues/192    \"Remove fs.createOutputStream()\"\n[#191]: https://github.com/jprichardson/node-fs-extra/issues/191    \"How to copy symlinks to target as normal folders [feature-copy]\"\n[#190]: https://github.com/jprichardson/node-fs-extra/pull/190      \"copySync to overwrite destination file if readonly and clobber true\"\n[#189]: https://github.com/jprichardson/node-fs-extra/pull/189      \"move.test fix to support CRLF on Windows\"\n[#188]: https://github.com/jprichardson/node-fs-extra/issues/188    \"move.test failing on windows platform\"\n[#187]: https://github.com/jprichardson/node-fs-extra/issues/187    \"Not filter each file, stops on first false [feature-copy]\"\n[#186]: https://github.com/jprichardson/node-fs-extra/issues/186    \"Do you need a .size() function in this module? [future]\"\n[#185]: https://github.com/jprichardson/node-fs-extra/issues/185    \"Doesn't work on NodeJS v4.x\"\n[#184]: https://github.com/jprichardson/node-fs-extra/issues/184    \"CLI equivalent for fs-extra\"\n[#183]: https://github.com/jprichardson/node-fs-extra/issues/183    \"with clobber true, copy and copySync behave differently if destination file is read only [bug, feature-copy]\"\n[#182]: https://github.com/jprichardson/node-fs-extra/issues/182    \"ensureDir(dir, callback) second callback parameter not specified\"\n[#181]: https://github.com/jprichardson/node-fs-extra/issues/181    \"Add ability to remove file securely [enhancement, wont-fix]\"\n[#180]: https://github.com/jprichardson/node-fs-extra/issues/180    \"Filter option doesn't work the same way in copy and copySync [bug, feature-copy]\"\n[#179]: https://github.com/jprichardson/node-fs-extra/issues/179    \"Include opendir\"\n[#178]: https://github.com/jprichardson/node-fs-extra/issues/178    \"ENOTEMPTY is thrown on removeSync \"\n[#177]: https://github.com/jprichardson/node-fs-extra/issues/177    \"fix `remove()` wildcards (introduced by rimraf) [feature-remove]\"\n[#176]: https://github.com/jprichardson/node-fs-extra/issues/176    \"createOutputStream doesn't emit 'end' event\"\n[#175]: https://github.com/jprichardson/node-fs-extra/issues/175    \"[Feature Request].moveSync support [feature-move, future]\"\n[#174]: https://github.com/jprichardson/node-fs-extra/pull/174      \"Fix copy formatting and document options.filter\"\n[#173]: https://github.com/jprichardson/node-fs-extra/issues/173    \"Feature Request: writeJson should mkdirs\"\n[#172]: https://github.com/jprichardson/node-fs-extra/issues/172    \"rename `clobber` flags to `overwrite`\"\n[#171]: https://github.com/jprichardson/node-fs-extra/issues/171    \"remove unnecessary aliases\"\n[#170]: https://github.com/jprichardson/node-fs-extra/pull/170      \"More robust handling of errors moving across virtual drives\"\n[#169]: https://github.com/jprichardson/node-fs-extra/pull/169      \"suppress ensureLink & ensureSymlink dest exists error\"\n[#168]: https://github.com/jprichardson/node-fs-extra/pull/168      \"suppress ensurelink dest exists error\"\n[#167]: https://github.com/jprichardson/node-fs-extra/pull/167      \"Adds basic (string, buffer) support for ensureFile content [future]\"\n[#166]: https://github.com/jprichardson/node-fs-extra/pull/166      \"Adds basic (string, buffer) support for ensureFile content\"\n[#165]: https://github.com/jprichardson/node-fs-extra/pull/165      \"ensure for link & symlink\"\n[#164]: https://github.com/jprichardson/node-fs-extra/issues/164    \"Feature Request: ensureFile to take optional argument for file content\"\n[#163]: https://github.com/jprichardson/node-fs-extra/issues/163    \"ouputJson not formatted out of the box [bug]\"\n[#162]: https://github.com/jprichardson/node-fs-extra/pull/162      \"ensure symlink & link\"\n[#161]: https://github.com/jprichardson/node-fs-extra/pull/161      \"ensure symlink & link\"\n[#160]: https://github.com/jprichardson/node-fs-extra/pull/160      \"ensure symlink & link\"\n[#159]: https://github.com/jprichardson/node-fs-extra/pull/159      \"ensure symlink & link\"\n[#158]: https://github.com/jprichardson/node-fs-extra/issues/158    \"Feature Request: ensureLink and ensureSymlink methods\"\n[#157]: https://github.com/jprichardson/node-fs-extra/issues/157    \"writeJson isn't formatted\"\n[#156]: https://github.com/jprichardson/node-fs-extra/issues/156    \"Promise.promisifyAll doesn't work for some methods\"\n[#155]: https://github.com/jprichardson/node-fs-extra/issues/155    \"Readme\"\n[#154]: https://github.com/jprichardson/node-fs-extra/issues/154    \"/tmp/millis-test-sync\"\n[#153]: https://github.com/jprichardson/node-fs-extra/pull/153      \"Make preserveTimes also work on read-only files. Closes #152\"\n[#152]: https://github.com/jprichardson/node-fs-extra/issues/152    \"fs.copy fails for read-only files with preserveTimestamp=true [feature-copy]\"\n[#151]: https://github.com/jprichardson/node-fs-extra/issues/151    \"TOC does not work correctly on npm [documentation]\"\n[#150]: https://github.com/jprichardson/node-fs-extra/issues/150    \"Remove test file fixtures, create with code.\"\n[#149]: https://github.com/jprichardson/node-fs-extra/issues/149    \"/tmp/millis-test-sync\"\n[#148]: https://github.com/jprichardson/node-fs-extra/issues/148    \"split out `Sync` methods in documentation\"\n[#147]: https://github.com/jprichardson/node-fs-extra/issues/147    \"Adding rmdirIfEmpty\"\n[#146]: https://github.com/jprichardson/node-fs-extra/pull/146      \"ensure test.js works\"\n[#145]: https://github.com/jprichardson/node-fs-extra/issues/145    \"Add `fs.exists` and `fs.existsSync` if it doesn't exist.\"\n[#144]: https://github.com/jprichardson/node-fs-extra/issues/144    \"tests failing\"\n[#143]: https://github.com/jprichardson/node-fs-extra/issues/143    \"update graceful-fs\"\n[#142]: https://github.com/jprichardson/node-fs-extra/issues/142    \"PrependFile Feature\"\n[#141]: https://github.com/jprichardson/node-fs-extra/pull/141      \"Add option to preserve timestamps\"\n[#140]: https://github.com/jprichardson/node-fs-extra/issues/140    \"Json file reading fails with 'utf8'\"\n[#139]: https://github.com/jprichardson/node-fs-extra/pull/139      \"Preserve file timestamp on copy. Closes #138\"\n[#138]: https://github.com/jprichardson/node-fs-extra/issues/138    \"Preserve timestamps on copying files\"\n[#137]: https://github.com/jprichardson/node-fs-extra/issues/137    \"outputFile/outputJson: Unexpected end of input\"\n[#136]: https://github.com/jprichardson/node-fs-extra/pull/136      \"Update license attribute\"\n[#135]: https://github.com/jprichardson/node-fs-extra/issues/135    \"emptyDir throws Error if no callback is provided\"\n[#134]: https://github.com/jprichardson/node-fs-extra/pull/134      \"Handle EEXIST error when clobbering dir\"\n[#133]: https://github.com/jprichardson/node-fs-extra/pull/133      \"Travis runs with `sudo: false`\"\n[#132]: https://github.com/jprichardson/node-fs-extra/pull/132      \"isDirectory method\"\n[#131]: https://github.com/jprichardson/node-fs-extra/issues/131    \"copySync is not working iojs 1.8.4 on linux [feature-copy]\"\n[#130]: https://github.com/jprichardson/node-fs-extra/pull/130      \"Please review additional features.\"\n[#129]: https://github.com/jprichardson/node-fs-extra/pull/129      \"can you review this feature?\"\n[#128]: https://github.com/jprichardson/node-fs-extra/issues/128    \"fsExtra.move(filepath, newPath) broken;\"\n[#127]: https://github.com/jprichardson/node-fs-extra/issues/127    \"consider using fs.access to remove deprecated warnings for fs.exists\"\n[#126]: https://github.com/jprichardson/node-fs-extra/issues/126    \" TypeError: Object #<Object> has no method 'access'\"\n[#125]: https://github.com/jprichardson/node-fs-extra/issues/125    \"Question: What do the *Sync function do different from non-sync\"\n[#124]: https://github.com/jprichardson/node-fs-extra/issues/124    \"move with clobber option 'ENOTEMPTY'\"\n[#123]: https://github.com/jprichardson/node-fs-extra/issues/123    \"Only copy the content of a directory\"\n[#122]: https://github.com/jprichardson/node-fs-extra/pull/122      \"Update section links in README to match current section ids.\"\n[#121]: https://github.com/jprichardson/node-fs-extra/issues/121    \"emptyDir is undefined\"\n[#120]: https://github.com/jprichardson/node-fs-extra/issues/120    \"usage bug caused by shallow cloning methods of 'graceful-fs'\"\n[#119]: https://github.com/jprichardson/node-fs-extra/issues/119    \"mkdirs and ensureDir never invoke callback and consume CPU indefinitely if provided a path with invalid characters on Windows\"\n[#118]: https://github.com/jprichardson/node-fs-extra/pull/118      \"createOutputStream\"\n[#117]: https://github.com/jprichardson/node-fs-extra/pull/117      \"Fixed issue with slash separated paths on windows\"\n[#116]: https://github.com/jprichardson/node-fs-extra/issues/116    \"copySync can only copy directories not files [documentation, feature-copy]\"\n[#115]: https://github.com/jprichardson/node-fs-extra/issues/115    \".Copy & .CopySync [feature-copy]\"\n[#114]: https://github.com/jprichardson/node-fs-extra/issues/114    \"Fails to move (rename) directory to non-empty directory even with clobber: true\"\n[#113]: https://github.com/jprichardson/node-fs-extra/issues/113    \"fs.copy seems to callback early if the destination file already exists\"\n[#112]: https://github.com/jprichardson/node-fs-extra/pull/112      \"Copying a file into an existing directory\"\n[#111]: https://github.com/jprichardson/node-fs-extra/pull/111      \"Moving a file into an existing directory \"\n[#110]: https://github.com/jprichardson/node-fs-extra/pull/110      \"Moving a file into an existing directory\"\n[#109]: https://github.com/jprichardson/node-fs-extra/issues/109    \"fs.move across windows drives fails\"\n[#108]: https://github.com/jprichardson/node-fs-extra/issues/108    \"fse.move directories across multiple devices doesn't work\"\n[#107]: https://github.com/jprichardson/node-fs-extra/pull/107      \"Check if dest path is an existing dir and copy or move source in it\"\n[#106]: https://github.com/jprichardson/node-fs-extra/issues/106    \"fse.copySync crashes while copying across devices D: [feature-copy]\"\n[#105]: https://github.com/jprichardson/node-fs-extra/issues/105    \"fs.copy hangs on iojs\"\n[#104]: https://github.com/jprichardson/node-fs-extra/issues/104    \"fse.move deletes folders [bug]\"\n[#103]: https://github.com/jprichardson/node-fs-extra/issues/103    \"Error: EMFILE with copy\"\n[#102]: https://github.com/jprichardson/node-fs-extra/issues/102    \"touch / touchSync was removed ?\"\n[#101]: https://github.com/jprichardson/node-fs-extra/issues/101    \"fs-extra promisified\"\n[#100]: https://github.com/jprichardson/node-fs-extra/pull/100      \"copy: options object or filter to pass to ncp\"\n[#99]: https://github.com/jprichardson/node-fs-extra/issues/99      \"ensureDir() modes [future]\"\n[#98]: https://github.com/jprichardson/node-fs-extra/issues/98      \"fs.copy() incorrect async behavior [bug]\"\n[#97]: https://github.com/jprichardson/node-fs-extra/pull/97        \"use path.join; fix copySync bug\"\n[#96]: https://github.com/jprichardson/node-fs-extra/issues/96      \"destFolderExists in copySync is always undefined.\"\n[#95]: https://github.com/jprichardson/node-fs-extra/pull/95        \"Using graceful-ncp instead of ncp\"\n[#94]: https://github.com/jprichardson/node-fs-extra/issues/94      \"Error: EEXIST, file already exists '../mkdirp/bin/cmd.js' on fs.copySync() [enhancement, feature-copy]\"\n[#93]: https://github.com/jprichardson/node-fs-extra/issues/93      \"Confusing error if drive not mounted [enhancement]\"\n[#92]: https://github.com/jprichardson/node-fs-extra/issues/92      \"Problems with Bluebird\"\n[#91]: https://github.com/jprichardson/node-fs-extra/issues/91      \"fs.copySync('/test', '/haha') is different with 'cp -r /test /haha' [enhancement]\"\n[#90]: https://github.com/jprichardson/node-fs-extra/issues/90      \"Folder creation and file copy is Happening in 64 bit machine but not in 32 bit machine\"\n[#89]: https://github.com/jprichardson/node-fs-extra/issues/89      \"Error: EEXIST using fs-extra's fs.copy to copy a directory on Windows\"\n[#88]: https://github.com/jprichardson/node-fs-extra/issues/88      \"Stacking those libraries\"\n[#87]: https://github.com/jprichardson/node-fs-extra/issues/87      \"createWriteStream + outputFile = ?\"\n[#86]: https://github.com/jprichardson/node-fs-extra/issues/86      \"no moveSync?\"\n[#85]: https://github.com/jprichardson/node-fs-extra/pull/85        \"Copy symlinks in copySync\"\n[#84]: https://github.com/jprichardson/node-fs-extra/issues/84      \"Push latest version to npm ?\"\n[#83]: https://github.com/jprichardson/node-fs-extra/issues/83      \"Prevent copying a directory into itself [feature-copy]\"\n[#82]: https://github.com/jprichardson/node-fs-extra/pull/82        \"README updates for move\"\n[#81]: https://github.com/jprichardson/node-fs-extra/issues/81      \"fd leak after fs.move\"\n[#80]: https://github.com/jprichardson/node-fs-extra/pull/80        \"Preserve file mode in copySync\"\n[#79]: https://github.com/jprichardson/node-fs-extra/issues/79      \"fs.copy only .html file empty\"\n[#78]: https://github.com/jprichardson/node-fs-extra/pull/78        \"copySync was not applying filters to directories\"\n[#77]: https://github.com/jprichardson/node-fs-extra/issues/77      \"Create README reference to bluebird\"\n[#76]: https://github.com/jprichardson/node-fs-extra/issues/76      \"Create README reference to typescript\"\n[#75]: https://github.com/jprichardson/node-fs-extra/issues/75      \"add glob as a dep? [question]\"\n[#74]: https://github.com/jprichardson/node-fs-extra/pull/74        \"including new emptydir module\"\n[#73]: https://github.com/jprichardson/node-fs-extra/pull/73        \"add dependency status in readme\"\n[#72]: https://github.com/jprichardson/node-fs-extra/pull/72        \"Use svg instead of png to get better image quality\"\n[#71]: https://github.com/jprichardson/node-fs-extra/issues/71      \"fse.copy not working on Windows 7 x64 OS, but, copySync does work\"\n[#70]: https://github.com/jprichardson/node-fs-extra/issues/70      \"Not filter each file, stops on first false [bug]\"\n[#69]: https://github.com/jprichardson/node-fs-extra/issues/69      \"How to check if folder exist and read the folder name\"\n[#68]: https://github.com/jprichardson/node-fs-extra/issues/68      \"consider flag to readJsonSync (throw false) [enhancement]\"\n[#67]: https://github.com/jprichardson/node-fs-extra/issues/67      \"docs for readJson incorrectly states that is accepts options\"\n[#66]: https://github.com/jprichardson/node-fs-extra/issues/66      \"ENAMETOOLONG\"\n[#65]: https://github.com/jprichardson/node-fs-extra/issues/65      \"exclude filter in fs.copy\"\n[#64]: https://github.com/jprichardson/node-fs-extra/issues/64      \"Announce: mfs - monitor your fs-extra calls\"\n[#63]: https://github.com/jprichardson/node-fs-extra/issues/63      \"Walk\"\n[#62]: https://github.com/jprichardson/node-fs-extra/issues/62      \"npm install fs-extra doesn't work\"\n[#61]: https://github.com/jprichardson/node-fs-extra/issues/61      \"No longer supports node 0.8 due to use of `^` in package.json dependencies\"\n[#60]: https://github.com/jprichardson/node-fs-extra/issues/60      \"chmod & chown for mkdirs\"\n[#59]: https://github.com/jprichardson/node-fs-extra/issues/59      \"Consider including mkdirp and making fs-extra '--use_strict' safe [question]\"\n[#58]: https://github.com/jprichardson/node-fs-extra/issues/58      \"Stack trace not included in fs.copy error\"\n[#57]: https://github.com/jprichardson/node-fs-extra/issues/57      \"Possible to include wildcards in delete?\"\n[#56]: https://github.com/jprichardson/node-fs-extra/issues/56      \"Crash when have no access to write to destination file in copy \"\n[#55]: https://github.com/jprichardson/node-fs-extra/issues/55      \"Is it possible to have any console output similar to Grunt copy module?\"\n[#54]: https://github.com/jprichardson/node-fs-extra/issues/54      \"`copy` does not preserve file ownership and permissons\"\n[#53]: https://github.com/jprichardson/node-fs-extra/issues/53      \"outputFile() - ability to write data in appending mode\"\n[#52]: https://github.com/jprichardson/node-fs-extra/pull/52        \"This fixes (what I think) is a bug in copySync\"\n[#51]: https://github.com/jprichardson/node-fs-extra/pull/51        \"Add a Bitdeli Badge to README\"\n[#50]: https://github.com/jprichardson/node-fs-extra/issues/50      \"Replace mechanism in createFile\"\n[#49]: https://github.com/jprichardson/node-fs-extra/pull/49        \"update rimraf to v2.2.6\"\n[#48]: https://github.com/jprichardson/node-fs-extra/issues/48      \"fs.copy issue [bug]\"\n[#47]: https://github.com/jprichardson/node-fs-extra/issues/47      \"Bug in copy - callback called on readStream 'close' - Fixed in ncp 0.5.0\"\n[#46]: https://github.com/jprichardson/node-fs-extra/pull/46        \"update copyright year\"\n[#45]: https://github.com/jprichardson/node-fs-extra/pull/45        \"Added note about fse.outputFile() being the one that overwrites\"\n[#44]: https://github.com/jprichardson/node-fs-extra/pull/44        \"Proposal: Stream support\"\n[#43]: https://github.com/jprichardson/node-fs-extra/issues/43      \"Better error reporting \"\n[#42]: https://github.com/jprichardson/node-fs-extra/issues/42      \"Performance issue?\"\n[#41]: https://github.com/jprichardson/node-fs-extra/pull/41        \"There does seem to be a synchronous version now\"\n[#40]: https://github.com/jprichardson/node-fs-extra/issues/40      \"fs.copy throw unexplained error ENOENT, utime \"\n[#39]: https://github.com/jprichardson/node-fs-extra/pull/39        \"Added regression test for copy() return callback on error\"\n[#38]: https://github.com/jprichardson/node-fs-extra/pull/38        \"Return err in copy() fstat cb, because stat could be undefined or null\"\n[#37]: https://github.com/jprichardson/node-fs-extra/issues/37      \"Maybe include a line reader? [enhancement, question]\"\n[#36]: https://github.com/jprichardson/node-fs-extra/pull/36        \"`filter` parameter `fs.copy` and `fs.copySync`\"\n[#35]: https://github.com/jprichardson/node-fs-extra/pull/35        \"`filter` parameter `fs.copy` and `fs.copySync` \"\n[#34]: https://github.com/jprichardson/node-fs-extra/issues/34      \"update docs to include options for JSON methods [enhancement]\"\n[#33]: https://github.com/jprichardson/node-fs-extra/pull/33        \"fs_extra.copySync\"\n[#32]: https://github.com/jprichardson/node-fs-extra/issues/32      \"update to latest jsonfile [enhancement]\"\n[#31]: https://github.com/jprichardson/node-fs-extra/issues/31      \"Add ensure methods [enhancement]\"\n[#30]: https://github.com/jprichardson/node-fs-extra/issues/30      \"update package.json optional dep `graceful-fs`\"\n[#29]: https://github.com/jprichardson/node-fs-extra/issues/29      \"Copy failing if dest directory doesn't exist. Is this intended?\"\n[#28]: https://github.com/jprichardson/node-fs-extra/issues/28      \"homepage field must be a string url. Deleted.\"\n[#27]: https://github.com/jprichardson/node-fs-extra/issues/27      \"Update Readme\"\n[#26]: https://github.com/jprichardson/node-fs-extra/issues/26      \"Add readdir recursive method. [enhancement]\"\n[#25]: https://github.com/jprichardson/node-fs-extra/pull/25        \"adding an `.npmignore` file\"\n[#24]: https://github.com/jprichardson/node-fs-extra/issues/24      \"[bug] cannot run in strict mode [bug]\"\n[#23]: https://github.com/jprichardson/node-fs-extra/issues/23      \"`writeJSON()` should create parent directories\"\n[#22]: https://github.com/jprichardson/node-fs-extra/pull/22        \"Add a limit option to mkdirs()\"\n[#21]: https://github.com/jprichardson/node-fs-extra/issues/21      \"touch() in 0.10.0\"\n[#20]: https://github.com/jprichardson/node-fs-extra/issues/20      \"fs.remove yields callback before directory is really deleted\"\n[#19]: https://github.com/jprichardson/node-fs-extra/issues/19      \"fs.copy err is empty array\"\n[#18]: https://github.com/jprichardson/node-fs-extra/pull/18        \"Exposed copyFile Function\"\n[#17]: https://github.com/jprichardson/node-fs-extra/issues/17      \"Use `require('graceful-fs')` if found instead of `require('fs')`\"\n[#16]: https://github.com/jprichardson/node-fs-extra/pull/16        \"Update README.md\"\n[#15]: https://github.com/jprichardson/node-fs-extra/issues/15      \"Implement cp -r but sync aka copySync. [enhancement]\"\n[#14]: https://github.com/jprichardson/node-fs-extra/issues/14      \"fs.mkdirSync is broken in 0.3.1\"\n[#13]: https://github.com/jprichardson/node-fs-extra/issues/13      \"Thoughts on including a directory tree / file watcher? [enhancement, question]\"\n[#12]: https://github.com/jprichardson/node-fs-extra/issues/12      \"copyFile & copyFileSync are global\"\n[#11]: https://github.com/jprichardson/node-fs-extra/issues/11      \"Thoughts on including a file walker? [enhancement, question]\"\n[#10]: https://github.com/jprichardson/node-fs-extra/issues/10      \"move / moveFile API [enhancement]\"\n[#9]: https://github.com/jprichardson/node-fs-extra/issues/9        \"don't import normal fs stuff into fs-extra\"\n[#8]: https://github.com/jprichardson/node-fs-extra/pull/8          \"Update rimraf to latest version\"\n[#6]: https://github.com/jprichardson/node-fs-extra/issues/6        \"Remove CoffeeScript development dependency\"\n[#5]: https://github.com/jprichardson/node-fs-extra/issues/5        \"comments on naming\"\n[#4]: https://github.com/jprichardson/node-fs-extra/issues/4        \"version bump to 0.2\"\n[#3]: https://github.com/jprichardson/node-fs-extra/pull/3          \"Hi! I fixed some code for you!\"\n[#2]: https://github.com/jprichardson/node-fs-extra/issues/2        \"Merge with fs.extra and mkdirp\"\n[#1]: https://github.com/jprichardson/node-fs-extra/issues/1        \"file-extra npm !exist\"\n"
  },
  {
    "path": "LICENSE",
    "content": "(The MIT License)\n\nCopyright (c) 2011-2024 JP Richardson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files\n(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,\n merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\nWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\nOR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "Node.js: fs-extra\n=================\n\n`fs-extra` adds file system methods that aren't included in the native `fs` module and adds promise support to the `fs` methods. It also uses [`graceful-fs`](https://github.com/isaacs/node-graceful-fs) to prevent `EMFILE` errors. It should be a drop in replacement for `fs`.\n\n[![npm Package](https://img.shields.io/npm/v/fs-extra.svg)](https://www.npmjs.org/package/fs-extra)\n[![License](https://img.shields.io/npm/l/fs-extra.svg)](https://github.com/jprichardson/node-fs-extra/blob/master/LICENSE)\n[![build status](https://img.shields.io/github/actions/workflow/status/jprichardson/node-fs-extra/ci.yml?branch=master)](https://github.com/jprichardson/node-fs-extra/actions/workflows/ci.yml?query=branch%3Amaster)\n[![downloads per month](http://img.shields.io/npm/dm/fs-extra.svg)](https://www.npmjs.org/package/fs-extra)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nWhy?\n----\n\nI got tired of including `mkdirp`, `rimraf`, and `ncp` in most of my projects.\n\n\n\n\nInstallation\n------------\n\n    npm install fs-extra\n\n\n\nUsage\n-----\n\n### CommonJS\n\n`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are attached to `fs-extra`. All `fs` methods return promises if the callback isn't passed.\n\nYou don't ever need to include the original `fs` module again:\n\n```js\nconst fs = require('fs') // this is no longer necessary\n```\n\nyou can now do this:\n\n```js\nconst fs = require('fs-extra')\n```\n\nor if you prefer to make it clear that you're using `fs-extra` and not `fs`, you may want\nto name your `fs` variable `fse` like so:\n\n```js\nconst fse = require('fs-extra')\n```\n\nyou can also keep both, but it's redundant:\n\n```js\nconst fs = require('fs')\nconst fse = require('fs-extra')\n```\n\n**NOTE:** The deprecated constants `fs.F_OK`, `fs.R_OK`, `fs.W_OK`, & `fs.X_OK` are not exported on Node.js v24.0.0+; please use their `fs.constants` equivalents. \n\n### ESM\n\nThere is also an `fs-extra/esm` import, that supports both default and named exports. However, note that `fs` methods are not included in `fs-extra/esm`; you still need to import `fs` and/or `fs/promises` seperately:\n\n```js\nimport { readFileSync } from 'fs'\nimport { readFile } from 'fs/promises'\nimport { outputFile, outputFileSync } from 'fs-extra/esm'\n```\n\nDefault exports are supported:\n\n```js\nimport fs from 'fs'\nimport fse from 'fs-extra/esm'\n// fse.readFileSync is not a function; must use fs.readFileSync\n```\n\nbut you probably want to just use regular `fs-extra` instead of `fs-extra/esm` for default exports:\n\n```js\nimport fs from 'fs-extra'\n// both fs and fs-extra methods are defined\n```\n\nSync vs Async vs Async/Await\n-------------\nMost methods are async by default. All async methods will return a promise if the callback isn't passed.\n\nSync methods on the other hand will throw if an error occurs.\n\nAlso Async/Await will throw an error if one occurs.\n\nExample:\n\n```js\nconst fs = require('fs-extra')\n\n// Async with promises:\nfs.copy('/tmp/myfile', '/tmp/mynewfile')\n  .then(() => console.log('success!'))\n  .catch(err => console.error(err))\n\n// Async with callbacks:\nfs.copy('/tmp/myfile', '/tmp/mynewfile', err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n\n// Sync:\ntry {\n  fs.copySync('/tmp/myfile', '/tmp/mynewfile')\n  console.log('success!')\n} catch (err) {\n  console.error(err)\n}\n\n// Async/Await:\nasync function copyFiles () {\n  try {\n    await fs.copy('/tmp/myfile', '/tmp/mynewfile')\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\ncopyFiles()\n```\n\n\nMethods\n-------\n\n### Async\n\n- [copy](docs/copy.md)\n- [emptyDir](docs/emptyDir.md)\n- [ensureFile](docs/ensureFile.md)\n- [ensureDir](docs/ensureDir.md)\n- [ensureLink](docs/ensureLink.md)\n- [ensureSymlink](docs/ensureSymlink.md)\n- [mkdirp](docs/ensureDir.md)\n- [mkdirs](docs/ensureDir.md)\n- [move](docs/move.md)\n- [outputFile](docs/outputFile.md)\n- [outputJson](docs/outputJson.md)\n- [pathExists](docs/pathExists.md)\n- [readJson](docs/readJson.md)\n- [remove](docs/remove.md)\n- [writeJson](docs/writeJson.md)\n\n### Sync\n\n- [copySync](docs/copy-sync.md)\n- [emptyDirSync](docs/emptyDir-sync.md)\n- [ensureFileSync](docs/ensureFile-sync.md)\n- [ensureDirSync](docs/ensureDir-sync.md)\n- [ensureLinkSync](docs/ensureLink-sync.md)\n- [ensureSymlinkSync](docs/ensureSymlink-sync.md)\n- [mkdirpSync](docs/ensureDir-sync.md)\n- [mkdirsSync](docs/ensureDir-sync.md)\n- [moveSync](docs/move-sync.md)\n- [outputFileSync](docs/outputFile-sync.md)\n- [outputJsonSync](docs/outputJson-sync.md)\n- [pathExistsSync](docs/pathExists-sync.md)\n- [readJsonSync](docs/readJson-sync.md)\n- [removeSync](docs/remove-sync.md)\n- [writeJsonSync](docs/writeJson-sync.md)\n\n\n**NOTE:** You can still use the native Node.js methods. They are promisified and copied over to `fs-extra`. See [notes on `fs.read()`, `fs.write()`, & `fs.writev()`](docs/fs-read-write-writev.md)\n\n### What happened to `walk()` and `walkSync()`?\n\nThey were removed from `fs-extra` in v2.0.0. If you need the functionality, `walk` and `walkSync` are available as separate packages, [`klaw`](https://github.com/jprichardson/node-klaw) and [`klaw-sync`](https://github.com/manidlou/node-klaw-sync).\n\n\nThird Party\n-----------\n\n### CLI\n\n[fse-cli](https://www.npmjs.com/package/@atao60/fse-cli) allows you to run `fs-extra` from a console or from [npm](https://www.npmjs.com) scripts.\n\n### TypeScript\n\nIf you like TypeScript, you can use `fs-extra` with it: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/fs-extra\n\n\n### File / Directory Watching\n\nIf you want to watch for changes to files or directories, then you should use [chokidar](https://github.com/paulmillr/chokidar).\n\n### Obtain Filesystem (Devices, Partitions) Information\n\n[fs-filesystem](https://github.com/arthurintelligence/node-fs-filesystem) allows you to read the state of the filesystem of the host on which it is run. It returns information about both the devices and the partitions (volumes) of the system.\n\n### Misc.\n\n- [fs-extra-debug](https://github.com/jdxcode/fs-extra-debug) - Send your fs-extra calls to [debug](https://npmjs.org/package/debug).\n- [mfs](https://github.com/cadorn/mfs) - Monitor your fs-extra calls.\n\n\n\nHacking on fs-extra\n-------------------\n\nWanna hack on `fs-extra`? Great! Your help is needed! [fs-extra is one of the most depended upon Node.js packages](http://nodei.co/npm/fs-extra.png?downloads=true&downloadRank=true&stars=true). This project\nuses [JavaScript Standard Style](https://github.com/feross/standard) - if the name or style choices bother you,\nyou're gonna have to get over it :) If `standard` is good enough for `npm`, it's good enough for `fs-extra`.\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\nWhat's needed?\n- First, take a look at existing issues. Those are probably going to be where the priority lies.\n- More tests for edge cases. Specifically on different platforms. There can never be enough tests.\n- Improve test coverage.\n\nNote: If you make any big changes, **you should definitely file an issue for discussion first.**\n\n### Running the Test Suite\n\nfs-extra contains hundreds of tests.\n\n- `npm run lint`: runs the linter ([standard](http://standardjs.com/))\n- `npm run unit`: runs the unit tests\n- `npm run unit-esm`: runs tests for `fs-extra/esm` exports\n- `npm test`: runs the linter and all tests\n\nWhen running unit tests, set the environment variable `CROSS_DEVICE_PATH` to the absolute path of an empty directory on another device (like a thumb drive) to enable cross-device move tests.\n\n\n### Windows\n\nIf you run the tests on the Windows and receive a lot of symbolic link `EPERM` permission errors, it's\nbecause on Windows you need elevated privilege to create symbolic links. You can add this to your Windows's\naccount by following the instructions here: http://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7\nHowever, I didn't have much luck doing this.\n\nSince I develop on Mac OS X, I use VMWare Fusion for Windows testing. I create a shared folder that I map to a drive on Windows.\nI open the `Node.js command prompt` and run as `Administrator`. I then map the network drive running the following command:\n\n    net use z: \"\\\\vmware-host\\Shared Folders\"\n\nI can then navigate to my `fs-extra` directory and run the tests.\n\n\nNaming\n------\n\nI put a lot of thought into the naming of these functions. Inspired by @coolaj86's request. So he deserves much of the credit for raising the issue. See discussion(s) here:\n\n* https://github.com/jprichardson/node-fs-extra/issues/2\n* https://github.com/flatiron/utile/issues/11\n* https://github.com/ryanmcgrath/wrench-js/issues/29\n* https://github.com/substack/node-mkdirp/issues/17\n\nFirst, I believe that in as many cases as possible, the [Node.js naming schemes](http://nodejs.org/api/fs.html) should be chosen. However, there are problems with the Node.js own naming schemes.\n\nFor example, `fs.readFile()` and `fs.readdir()`: the **F** is capitalized in *File* and the **d** is not capitalized in *dir*. Perhaps a bit pedantic, but they should still be consistent. Also, Node.js has chosen a lot of POSIX naming schemes, which I believe is great. See: `fs.mkdir()`, `fs.rmdir()`, `fs.chown()`, etc.\n\nWe have a dilemma though. How do you consistently name methods that perform the following POSIX commands: `cp`, `cp -r`, `mkdir -p`, and `rm -rf`?\n\nMy perspective: when in doubt, err on the side of simplicity. A directory is just a hierarchical grouping of directories and files. Consider that for a moment. So when you want to copy it or remove it, in most cases you'll want to copy or remove all of its contents. When you want to create a directory, if the directory that it's suppose to be contained in does not exist, then in most cases you'll want to create that too.\n\nSo, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(path)`. If you want to copy a file or a directory whether it has contents, just call `fs.copy(source, destination)`. If you want to create a directory regardless of whether its parent directories exist, just call `fs.mkdirs(path)` or `fs.mkdirp(path)`.\n\n\nCredit\n------\n\n`fs-extra` wouldn't be possible without using the modules from the following authors:\n\n- [Isaac Shlueter](https://github.com/isaacs)\n- [Charlie McConnel](https://github.com/avianflu)\n- [James Halliday](https://github.com/substack)\n- [Andrew Kelley](https://github.com/andrewrk)\n\n\n\n\nLicense\n-------\n\nLicensed under MIT\n\nCopyright (c) 2011-2024 [JP Richardson](https://github.com/jprichardson)\n\n[1]: http://nodejs.org/docs/latest/api/fs.html\n\n\n[jsonfile]: https://github.com/jprichardson/node-jsonfile\n"
  },
  {
    "path": "docs/copy-sync.md",
    "content": "# copySync(src, dest[, options])\n\nCopy a file or directory. The directory can have contents.\n\n- `src` `<String>` Note that if `src` is a directory it will copy everything inside of this directory, not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).\n- `dest` `<String>` Note that if `src` is a file, `dest` cannot be a directory (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).\n- `options` `<Object>`\n  - `overwrite` `<boolean>`: overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.\n  - `errorOnExist` `<boolean>`: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.\n  - `dereference` `<boolean>`: dereference symlinks, default is `false`.\n  - `preserveTimestamps` `<boolean>`: When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. Default is `false`.\n  - `filter` `<Function>`: Function to filter copied files/directories. Return `true` to copy the item, `false` to ignore it.\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// copy file\nfs.copySync('/tmp/myfile', '/tmp/mynewfile')\n\n// copy directory, even if it has subdirectories or files\nfs.copySync('/tmp/mydir', '/tmp/mynewdir')\n```\n\n**Using filter function**\n\n```js\nconst fs = require('fs-extra')\n\nconst filterFunc = (src, dest) => {\n  // your logic here\n  // it will be copied if return true\n}\n\nfs.copySync('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc })\n```\n"
  },
  {
    "path": "docs/copy.md",
    "content": "# copy(src, dest[, options][, callback])\n\nCopy a file or directory. The directory can have contents.\n\n- `src` `<String>` Note that if `src` is a directory it will copy everything inside of this directory, not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).\n- `dest` `<String>` Note that if `src` is a file, `dest` cannot be a directory (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).\n- `options` `<Object>`\n  - `overwrite` `<boolean>`: overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.\n  - `errorOnExist` `<boolean>`: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.\n  - `dereference` `<boolean>`: dereference symlinks, default is `false`.\n  - `preserveTimestamps` `<boolean>`: When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent. Default is `false`.\n  - `filter` `<Function>`: Function to filter copied files/directories. Return `true` to copy the item, `false` to ignore it. Can also return a `Promise` that resolves to `true` or `false` (or pass in an `async` function).\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// With a callback:\nfs.copy('/tmp/myfile', '/tmp/mynewfile', err => {\n  if (err) return console.error(err)\n  console.log('success!')\n}) // copies file\n\nfs.copy('/tmp/mydir', '/tmp/mynewdir', err => {\n  if (err) return console.error(err)\n  console.log('success!')\n}) // copies directory, even if it has subdirectories or files\n\n// With Promises:\nfs.copy('/tmp/myfile', '/tmp/mynewfile')\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example () {\n  try {\n    await fs.copy('/tmp/myfile', '/tmp/mynewfile')\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample()\n```\n\n**Using filter function**\n\n```js\nconst fs = require('fs-extra')\n\nconst filterFunc = (src, dest) => {\n  // your logic here\n  // it will be copied if return true\n}\n\nfs.copy('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc }, err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n```\n"
  },
  {
    "path": "docs/emptyDir-sync.md",
    "content": "# emptyDirSync(dir)\n\nEnsures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.\n\n**Alias:** `emptydirSync()`\n\n- `dir` `<String>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// assume this directory has a lot of files and folders\nfs.emptyDirSync('/tmp/some/dir')\n```\n"
  },
  {
    "path": "docs/emptyDir.md",
    "content": "# emptyDir(dir[, callback])\n\nEnsures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.\n\n**Alias:** `emptydir()`\n\n- `dir` `<String>`\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// assume this directory has a lot of files and folders\n// With a callback:\nfs.emptyDir('/tmp/some/dir', err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n\n// With Promises:\nfs.emptyDir('/tmp/some/dir')\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example () {\n  try {\n    await fs.emptyDir('/tmp/some/dir')\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample()\n```\n"
  },
  {
    "path": "docs/ensureDir-sync.md",
    "content": "# ensureDirSync(dir[,options])\n\nEnsures that the directory exists. If the directory structure does not exist, it is created. If provided, options may specify the desired mode for the directory. \n\n**Aliases:** `mkdirsSync()`, `mkdirpSync()`\n\n- `dir` `<String>`\n- `options` `<Integer> | <Object>`\n  - If it is `Integer`, it will be `mode`.\n  - If it is `Object`, it will be `{ mode: <Integer> }`.\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst dir = '/tmp/this/path/does/not/exist'\n\nconst desiredMode = 0o2775\nconst options = {\n  mode: 0o2775\n}\n\nfs.ensureDirSync(dir)\n// dir has now been created, including the directory it is to be placed in\n\nfs.ensureDirSync(dir, desiredMode)\n// dir has now been created, including the directory it is to be placed in with permission 0o2775\n\nfs.ensureDirSync(dir, options)\n// dir has now been created, including the directory it is to be placed in with permission 0o2775\n```\n"
  },
  {
    "path": "docs/ensureDir.md",
    "content": "# ensureDir(dir[,options][,callback])\n\nEnsures that the directory exists. If the directory structure does not exist, it is created.\n\n**Aliases:** `mkdirs()`, `mkdirp()`\n\n- `dir` `<String>`\n- `options` `<Integer> | <Object>`\n  - If it is `Integer`, it will be `mode`.\n  - If it is `Object`, it will be `{ mode: <Integer> }`.\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst dir = '/tmp/this/path/does/not/exist'\nconst desiredMode = 0o2775\nconst options = {\n  mode: 0o2775\n}\n\n// With a callback:\nfs.ensureDir(dir, err => {\n  console.log(err) // => null\n  // dir has now been created, including the directory it is to be placed in\n})\n\n// With a callback and a mode integer\nfs.ensureDir(dir, desiredMode, err => {\n  console.log(err) // => null\n  // dir has now been created with mode 0o2775, including the directory it is to be placed in\n})\n\n// With Promises:\nfs.ensureDir(dir)\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With Promises and a mode integer:\nfs.ensureDir(dir, desiredMode)\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (directory) {\n  try {\n    await fs.ensureDir(directory)\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\nexample(dir)\n\n// With async/await and an options object, containing mode:\nasync function exampleMode (directory) {\n  try {\n    await fs.ensureDir(directory, options)\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\nexampleMode(dir)\n```\n"
  },
  {
    "path": "docs/ensureFile-sync.md",
    "content": "# ensureFileSync(file)\n\nEnsures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.\n\n**Alias:** `createFileSync()`\n\n- `file` `<String>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureFileSync(file)\n// file has now been created, including the directory it is to be placed in\n```\n"
  },
  {
    "path": "docs/ensureFile.md",
    "content": "# ensureFile(file[, callback])\n\nEnsures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.\n\n**Alias:** `createFile()`\n\n- `file` `<String>`\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/this/path/does/not/exist/file.txt'\n\n// With a callback:\nfs.ensureFile(file, err => {\n  console.log(err) // => null\n  // file has now been created, including the directory it is to be placed in\n})\n\n// With Promises:\nfs.ensureFile(file)\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (f) {\n  try {\n    await fs.ensureFile(f)\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample(file)\n```\n"
  },
  {
    "path": "docs/ensureLink-sync.md",
    "content": "# ensureLinkSync(srcPath, destPath)\n\nEnsures that the link exists. If the directory structure does not exist, it is created.\n\n**Alias:** `createLinkSync()`\n\n- `srcPath` `<String>`\n- `destPath` `<String>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst srcPath = '/tmp/file.txt'\nconst destPath = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureLinkSync(srcPath, destPath)\n// link has now been created, including the directory it is to be placed in\n```\n"
  },
  {
    "path": "docs/ensureLink.md",
    "content": "# ensureLink(srcPath, destPath[, callback])\n\nEnsures that the link exists. If the directory structure does not exist, it is created.\n\n**Alias:** `createLink()`\n\n- `srcPath` `<String>`\n- `destPath` `<String>`\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst srcPath = '/tmp/file.txt'\nconst destPath = '/tmp/this/path/does/not/exist/file.txt'\n\n// With a callback:\nfs.ensureLink(srcPath, destPath, err => {\n  console.log(err) // => null\n  // link has now been created, including the directory it is to be placed in\n})\n\n// With Promises:\nfs.ensureLink(srcPath, destPath)\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (src, dest) {\n  try {\n    await fs.ensureLink(src, dest)\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample(srcPath, destPath)\n```\n"
  },
  {
    "path": "docs/ensureSymlink-sync.md",
    "content": "# ensureSymlinkSync(srcPath, destPath[, type])\n\nEnsures that the symlink exists. If the directory structure does not exist, it is created.\n\n**Alias:** `createSymlinkSync()`\n\n- `srcPath` `<String>`\n- `destPath` `<String>`\n- `type` `<String>` It is only available on Windows and ignored on other platforms. It can be set to `dir`, `file`, or `junction`.\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst srcPath = '/tmp/file.txt'\nconst destPath = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureSymlinkSync(srcPath, destPath)\n// symlink has now been created, including the directory it is to be placed in\n```\n"
  },
  {
    "path": "docs/ensureSymlink.md",
    "content": "# ensureSymlink(srcPath, destPath[, type][, callback])\n\nEnsures that the symlink exists. If the directory structure does not exist, it is created.\n\n**Alias:** `createSymlink()`\n\n- `srcPath` `<String>`\n- `destPath` `<String>`\n- `type` `<String>` It is only available on Windows and ignored on other platforms. It can be set to `dir`, `file`, or `junction`.\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst srcPath = '/tmp/file.txt'\nconst destPath = '/tmp/this/path/does/not/exist/file.txt'\n\n// With a callback:\nfs.ensureSymlink(srcPath, destPath, err => {\n  console.log(err) // => null\n  // symlink has now been created, including the directory it is to be placed in\n})\n\n// With Promises:\nfs.ensureSymlink(srcPath, destPath)\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (src, dest) {\n  try {\n    await fs.ensureSymlink(src, dest)\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample(srcPath, destPath)\n```\n"
  },
  {
    "path": "docs/fs-read-write-writev.md",
    "content": "# About `fs.read()` & `fs.write()`\n\n[`fs.read()`](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback), [`fs.write()`](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback), & [`fs.writev()`](https://nodejs.org/api/fs.html#fs_fs_writev_fd_buffers_position_callback) are different from other `fs` methods in that their callbacks are called with 3 arguments instead of the usual 2 arguments.\n\nIf you're using them with callbacks, they will behave as usual. However, their promise usage is a little different. `fs-extra` promisifies these methods like [`util.promisify()`](https://nodejs.org/api/util.html#util_util_promisify_original) (only available in Node 8+) does.\n\nHere's the example promise usage:\n\n## `fs.read()`\n\n```js\n// With Promises:\nfs.read(fd, buffer, offset, length, position)\n  .then(results => {\n    console.log(results)\n    // { bytesRead: 20, buffer: <Buffer 0f 34 5d ...> }\n  })\n\n// With async/await:\nasync function example () {\n  const { bytesRead, buffer } = await fs.read(fd, Buffer.alloc(length), offset, length, position)\n}\n```\n\n## `fs.write()`\n\n```js\n// With Promises:\nfs.write(fd, buffer, offset, length, position)\n  .then(results => {\n    console.log(results)\n    // { bytesWritten: 20, buffer: <Buffer 0f 34 5d ...> }\n  })\n\n// With async/await:\nasync function example () {\n  const { bytesWritten, buffer } = await fs.write(fd, Buffer.alloc(length), offset, length, position)\n}\n```\n\n## `fs.writev()`\n\n```js\n// With async/await:\nasync function example () {\n  const { bytesWritten, buffers } = await fs.writev(fd, buffers, position)\n}\n```\n"
  },
  {
    "path": "docs/move-sync.md",
    "content": "# moveSync(src, dest[, options])\n\nMoves a file or directory, even across devices.\n\n- `src` `<String>`\n- `dest` `<String>` Note: When `src` is a file, `dest` must be a file and when `src` is a directory, `dest` must be a directory.\n- `options` `<Object>`\n  - `overwrite` `<boolean>`: overwrite existing file or directory, default is `false`.\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nfs.moveSync('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')\n```\n\n**Using `overwrite` option**\n\n```js\nconst fs = require('fs-extra')\n\nfs.moveSync('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true })\n```\n"
  },
  {
    "path": "docs/move.md",
    "content": "# move(src, dest[, options][, callback])\n\nMoves a file or directory, even across devices.\n\n- `src` `<String>`\n- `dest` `<String>` Note: When `src` is a file, `dest` must be a file and when `src` is a directory, `dest` must be a directory.\n- `options` `<Object>`\n  - `overwrite` `<boolean>`: overwrite existing file or directory, default is `false`.\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst src = '/tmp/file.txt'\nconst dest = '/tmp/this/path/does/not/exist/file.txt'\n\n// With a callback:\nfs.move(src, dest, err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n\n// With Promises:\nfs.move(src, dest)\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (src, dest) {\n  try {\n    await fs.move(src, dest)\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample(src, dest)\n```\n\n**Using `overwrite` option**\n\n```js\nconst fs = require('fs-extra')\n\nfs.move('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true }, err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n```\n"
  },
  {
    "path": "docs/outputFile-sync.md",
    "content": "# outputFileSync(file, data[, options])\n\nAlmost the same as `writeFileSync` (i.e. it overwrites), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed).\n\n- `file` `<String>`\n- `data` `<String> | <Buffer> | <Uint8Array>`\n- `options` `<Object> | <String>` (the same as [`fs.writeFileSync()` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options))\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/this/path/does/not/exist/file.txt'\nfs.outputFileSync(file, 'hello!')\n\nconst data = fs.readFileSync(file, 'utf8')\nconsole.log(data) // => hello!\n```\n"
  },
  {
    "path": "docs/outputFile.md",
    "content": "# outputFile(file, data[, options][, callback])\n\nAlmost the same as `writeFile` (i.e. it overwrites), except that if the parent directory does not exist, it's created. `file` must be a file path (a buffer or a file descriptor is not allowed).\n\n- `file` `<String>`\n- `data` `<String> | <Buffer> | <Uint8Array>`\n- `options` `<Object> | <String>` (the same as [`fs.writeFile()` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback))\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/this/path/does/not/exist/file.txt'\n\n// With a callback:\nfs.outputFile(file, 'hello!', err => {\n  console.log(err) // => null\n\n  fs.readFile(file, 'utf8', (err, data) => {\n    if (err) return console.error(err)\n    console.log(data) // => hello!\n  })\n})\n\n// With Promises:\nfs.outputFile(file, 'hello!')\n.then(() => fs.readFile(file, 'utf8'))\n.then(data => {\n  console.log(data) // => hello!\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (f) {\n  try {\n    await fs.outputFile(f, 'hello!')\n\n    const data = await fs.readFile(f, 'utf8')\n\n    console.log(data) // => hello!\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample(file)\n```\n"
  },
  {
    "path": "docs/outputJson-sync.md",
    "content": "# outputJsonSync(file, object[, options])\n\nAlmost the same as [`writeJsonSync`](writeJson-sync.md), except that if the directory does not exist, it's created.\n\n**Alias:** `outputJSONSync()`\n\n- `file` `<String>`\n- `object` `<Object>`\n- `options` `<Object>`\n  - `spaces` `<Number> | <String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.\n  - `EOL` `<String>` Set EOL character. Default is `\\n`.\n  - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)\n  - Also accepts [`fs.writeFileSync()` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/this/path/does/not/exist/file.json'\nfs.outputJsonSync(file, {name: 'JP'})\n\nconst data = fs.readJsonSync(file)\nconsole.log(data.name) // => JP\n```\n"
  },
  {
    "path": "docs/outputJson.md",
    "content": "# outputJson(file, object[, options][, callback])\n\nAlmost the same as [`writeJson`](writeJson.md), except that if the directory does not exist, it's created.\n\n**Alias:** `outputJSON()`\n\n- `file` `<String>`\n- `object` `<Object>`\n- `options` `<Object>`\n  - `spaces` `<Number> | <String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.\n  - `EOL` `<String>` Set EOL character. Default is `\\n`.\n  - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)\n  - Also accepts [`fs.writeFile()` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/this/path/does/not/exist/file.json'\n\n// With a callback:\nfs.outputJson(file, {name: 'JP'}, err => {\n  console.log(err) // => null\n\n  fs.readJson(file, (err, data) => {\n    if (err) return console.error(err)\n    console.log(data.name) // => JP\n  })\n})\n\n// With Promises:\nfs.outputJson(file, {name: 'JP'})\n.then(() => fs.readJson(file))\n.then(data => {\n  console.log(data.name) // => JP\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (f) {\n  try {\n    await fs.outputJson(f, {name: 'JP'})\n\n    const data = await fs.readJson(f)\n\n    console.log(data.name) // => JP\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample(file)\n```\n"
  },
  {
    "path": "docs/pathExists-sync.md",
    "content": "# pathExistsSync(file)\n\nAn alias for [`fs.existsSync()`](https://nodejs.org/api/fs.html#fs_fs_existssync_path), created for consistency with [`pathExists()`](pathExists.md).\n"
  },
  {
    "path": "docs/pathExists.md",
    "content": "# pathExists(file[, callback])\n\nTest whether or not the given path exists by checking with the file system. Like [`fs.exists`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback), but with a normal callback signature (err, exists). Uses `fs.access` under the hood.\n\n- `file` `<String>`\n- `callback` `<Function>`\n  - `err` `<Error>`\n  - `exists` `<boolean>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/this/path/does/not/exist/file.txt'\n\n// With a callback:\nfs.pathExists(file, (err, exists) => {\n  console.log(err) // => null\n  console.log(exists) // => false\n})\n\n// Promise usage:\nfs.pathExists(file)\n  .then(exists => console.log(exists)) // => false\n\n// With async/await:\nasync function example (f) {\n  const exists = await fs.pathExists(f)\n\n  console.log(exists) // => false\n}\n\nexample(file)\n```\n"
  },
  {
    "path": "docs/readJson-sync.md",
    "content": "# readJsonSync(file[, options])\n\nReads a JSON file and then parses it into an object.\n\n**Alias:** `readJSONSync()`\n\n- `file` `<String>`\n- `options` `<Object>` (the same as [`jsonFile.readFileSync()` options](https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options))\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst packageObj = fs.readJsonSync('./package.json')\nconsole.log(packageObj.version) // => 2.0.0\n```\n\n---\n\n`readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/some-invalid.json'\nconst data = '{not valid JSON'\nfs.writeFileSync(file, data)\n\nconst obj = fs.readJsonSync(file, { throws: false })\nconsole.log(obj) // => null\n```\n"
  },
  {
    "path": "docs/readJson.md",
    "content": "# readJson(file[, options][, callback])\n\nReads a JSON file and then parses it into an object.\n\n**Alias:** `readJSON()`\n\n- `file` `<String>`\n- `options` `<Object>` (the same as [`jsonFile.readFile()` options](https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback))\n- `callback` `<Function>`\n  - `err` `<Error>`\n  - `obj` `<Object>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// With a callback:\nfs.readJson('./package.json', (err, packageObj) => {\n  if (err) console.error(err)\n  console.log(packageObj.version) // => 0.1.3\n})\n\n// With Promises:\nfs.readJson('./package.json')\n.then(packageObj => {\n  console.log(packageObj.version) // => 0.1.3\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example () {\n  try {\n    const packageObj = await fs.readJson('./package.json')\n    console.log(packageObj.version) // => 0.1.3\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample()\n```\n\n---\n\n`readJson()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:\n\n```js\nconst fs = require('fs-extra')\n\nconst file = '/tmp/some-invalid.json'\nconst data = '{not valid JSON'\nfs.writeFileSync(file, data)\n\n// With a callback:\nfs.readJson(file, { throws: false }, (err, obj) => {\n  if (err) console.error(err)\n  console.log(obj) // => null\n})\n\n// With Promises:\nfs.readJson(file, { throws: false })\n.then(obj => {\n  console.log(obj) // => null\n})\n.catch(err => {\n  console.error(err) // Not called\n})\n\n// With async/await:\nasync function example (f) {\n  const obj = await fs.readJson(f, { throws: false })\n  console.log(obj) // => null\n}\n\nexample(file)\n```\n"
  },
  {
    "path": "docs/remove-sync.md",
    "content": "# removeSync(path)\n\nRemoves a file or directory. The directory can have contents. If the path does not exist, silently does nothing.\n\n- `path` `<String>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// remove file\nfs.removeSync('/tmp/myfile')\n\nfs.removeSync('/home/jprichardson') // I just deleted my entire HOME directory.\n```\n"
  },
  {
    "path": "docs/remove.md",
    "content": "# remove(path[, callback])\n\nRemoves a file or directory. The directory can have contents. If the path does not exist, silently does nothing.\n\n- `path` `<String>`\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// remove file\n// With a callback:\nfs.remove('/tmp/myfile', err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n\nfs.remove('/home/jprichardson', err => {\n  if (err) return console.error(err)\n  console.log('success!') // I just deleted my entire HOME directory.\n})\n\n// With Promises:\nfs.remove('/tmp/myfile')\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example (src, dest) {\n  try {\n    await fs.remove('/tmp/myfile')\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample()\n```\n"
  },
  {
    "path": "docs/writeJson-sync.md",
    "content": "# writeJsonSync(file, object[, options])\n\nWrites an object to a JSON file.\n\n**Alias:** `writeJSONSync()`\n\n- `file` `<String>`\n- `object` `<Object>`\n- `options` `<Object>`\n  - `spaces` `<Number> | <String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.\n  - `EOL` `<String>` Set EOL character. Default is `\\n`.\n  - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)\n  - Also accepts [`fs.writeFileSync()` options](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\nfs.writeJsonSync('./package.json', {name: 'fs-extra'})\n```\n---\n\n**See also:** [`outputJsonSync()`](outputJson-sync.md)\n"
  },
  {
    "path": "docs/writeJson.md",
    "content": "# writeJson(file, object[, options][, callback])\n\nWrites an object to a JSON file.\n\n**Alias:** `writeJSON()`\n\n- `file` `<String>`\n- `object` `<Object>`\n- `options` `<Object>`\n  - `spaces` `<Number> | <String>` Number of spaces to indent; or a string to use for indentation (i.e. pass `'\\t'` for tab indentation). See [the docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) for more info.\n  - `EOL` `<String>` Set EOL character. Default is `\\n`.\n  - `replacer` [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter)\n  - Also accepts [`fs.writeFile()` options](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback)\n- `callback` `<Function>`\n  - `err` `<Error>`\n\n## Example:\n\n```js\nconst fs = require('fs-extra')\n\n// With a callback:\nfs.writeJson('./package.json', {name: 'fs-extra'}, err => {\n  if (err) return console.error(err)\n  console.log('success!')\n})\n\n// With Promises:\nfs.writeJson('./package.json', {name: 'fs-extra'})\n.then(() => {\n  console.log('success!')\n})\n.catch(err => {\n  console.error(err)\n})\n\n// With async/await:\nasync function example () {\n  try {\n    await fs.writeJson('./package.json', {name: 'fs-extra'})\n    console.log('success!')\n  } catch (err) {\n    console.error(err)\n  }\n}\n\nexample()\n```\n\n---\n\n**See also:** [`outputJson()`](outputJson.md)\n"
  },
  {
    "path": "lib/__tests__/promise.test.js",
    "content": "'use strict'\n\n/* eslint-env mocha */\n\nconst assert = require('assert')\nconst fse = require('..')\n\nconst methods = [\n  'emptyDir',\n  'ensureFile',\n  'ensureDir',\n  'mkdirs',\n  'readJson',\n  'readJSON',\n  'remove'\n]\n\ndescribe('promise support', () => {\n  methods.forEach(method => {\n    it(method, done => {\n      fse[method]().catch(() => done())\n    })\n  })\n\n  it('provides fse.promises API', () => {\n    assert.ok(fse.promises)\n    assert.strictEqual(typeof fse.promises.writeFile, 'function')\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-broken-symlink.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst { copy } = require('../')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('copy / broken symlink', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-broken-symlink')\n  const src = path.join(TEST_DIR, 'src')\n  const dest = path.join(TEST_DIR, 'dest')\n\n  beforeEach(done => {\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n      createFixtures(src, done)\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('when symlink is broken', () => {\n    it('should not throw error if dereference is false', done => {\n      copy(src, dest, err => {\n        assert.strictEqual(err, null)\n        done()\n      })\n    })\n\n    it('should throw error if dereference is true', done => {\n      copy(src, dest, { dereference: true }, err => {\n        assert.strictEqual(err.code, 'ENOENT')\n        done()\n      })\n    })\n  })\n})\n\nfunction createFixtures (srcDir, callback) {\n  fs.mkdir(srcDir, err => {\n    let brokenFile\n    let brokenFileLink\n\n    if (err) return callback(err)\n\n    try {\n      brokenFile = path.join(srcDir, 'does-not-exist')\n      brokenFileLink = path.join(srcDir, 'broken-symlink')\n      fs.writeFileSync(brokenFile, 'does not matter')\n      fs.symlinkSync(brokenFile, brokenFileLink, 'file')\n    } catch (err) {\n      callback(err)\n    }\n\n    // break the symlink now\n    fse.remove(brokenFile, callback)\n  })\n}\n"
  },
  {
    "path": "lib/copy/__tests__/copy-case-insensitive-paths.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst platform = os.platform()\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ copy() - case insensitive paths', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-case-insensitive-paths')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when src is a directory', () => {\n    it('should behave correctly based on the OS', done => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      dest = path.join(TEST_DIR, 'srcDir')\n\n      fs.copy(src, dest, err => {\n        if (platform === 'linux') {\n          assert.ifError(err)\n          assert(fs.existsSync(dest))\n          assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n        }\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n        done()\n      })\n    })\n  })\n\n  describe('> when src is a file', () => {\n    it('should behave correctly based on the OS', done => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      dest = path.join(TEST_DIR, 'srcFile')\n\n      fs.copy(src, dest, err => {\n        if (platform === 'linux') {\n          assert.ifError(err)\n          assert(fs.existsSync(dest))\n          assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n        }\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n        done()\n      })\n    })\n  })\n\n  describe('> when src is a symlink', () => {\n    it('should behave correctly based on the OS, symlink dir', done => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'dir')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n\n      fs.copy(srcLink, dest, err => {\n        if (platform === 'linux') {\n          assert.ifError(err)\n          assert(fs.existsSync(dest))\n          assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n          const destLink = fs.readlinkSync(dest)\n          assert.strictEqual(destLink, src)\n        }\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n        done()\n      })\n    })\n\n    it('should behave correctly based on the OS, symlink file', done => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'file')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n\n      fs.copy(srcLink, dest, err => {\n        if (platform === 'linux') {\n          assert.ifError(err)\n          assert(fs.existsSync(dest))\n          assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n          const destLink = fs.readlinkSync(dest)\n          assert.strictEqual(destLink, src)\n        }\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-dev-null.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\nlet TEST_DIR = ''\n\ndescribe('+ copy() - copy /dev/null', () => {\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'test', 'fs-extra', 'copy-dev-null')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('> when src is /dev/null', () => {\n    it('should copy successfully', done => {\n      // no /dev/null on windows\n      if (process.platform === 'win32') return done()\n\n      const tmpFile = path.join(TEST_DIR, 'foo')\n\n      fse.copy('/dev/null', tmpFile, err => {\n        assert.ifError(err)\n        const stats = fs.lstatSync(tmpFile)\n        assert.strictEqual(stats.size, 0)\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-gh-89.test.js",
    "content": "'use strict'\n\n// relevant: https://github.com/jprichardson/node-fs-extra/issues/89\n// come up with better file name\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('copy() - gh #89', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-gh-89')\n\n  beforeEach(done => {\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => {\n    fse.remove(TEST_DIR, done)\n  })\n\n  it('should copy successfully', done => {\n    const A = path.join(TEST_DIR, 'A')\n    const B = path.join(TEST_DIR, 'B')\n    fs.mkdirSync(A)\n    fs.mkdirSync(B)\n\n    const one = path.join(A, 'one.txt')\n    const two = path.join(A, 'two.txt')\n    const three = path.join(B, 'three.txt')\n    const four = path.join(B, 'four.txt')\n\n    fs.writeFileSync(one, '1')\n    fs.writeFileSync(two, '2')\n    fs.writeFileSync(three, '3')\n    fs.writeFileSync(four, '4')\n\n    const C = path.join(TEST_DIR, 'C')\n    fse.copy(A, C, err => {\n      if (err) return done(err)\n\n      fse.copy(B, C, err => {\n        if (err) return done(err)\n\n        assert(fs.existsSync(path.join(C, 'one.txt')))\n        assert(fs.existsSync(path.join(C, 'two.txt')))\n        assert(fs.existsSync(path.join(C, 'three.txt')))\n        assert(fs.existsSync(path.join(C, 'four.txt')))\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-permissions.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global beforeEach, describe, it */\n\ndescribe('copy', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  // pretty UNIX specific, may not pass on windows... only tested on Mac OS X 10.9\n  it('should maintain file permissions and ownership', done => {\n    if (process.platform === 'win32') return done()\n\n    // var userid = require('userid')\n\n    // http://man7.org/linux/man-pages/man2/stat.2.html\n    const S_IFREG = 0o100000 // regular file\n    const S_IFDIR = 0o40000 // directory\n\n    // these are Mac specific I think (at least staff), should find Linux equivalent\n    let gidWheel\n    let gidStaff\n\n    try {\n      gidWheel = process.getgid() // userid.gid('wheel')\n    } catch {\n      gidWheel = process.getgid()\n    }\n\n    try {\n      gidStaff = process.getgid() // userid.gid('staff')\n    } catch {\n      gidStaff = process.getgid()\n    }\n\n    const permDir = path.join(TEST_DIR, 'perms')\n    fs.mkdirSync(permDir)\n\n    const srcDir = path.join(permDir, 'src')\n    fs.mkdirSync(srcDir)\n\n    const f1 = path.join(srcDir, 'f1.txt')\n    fs.writeFileSync(f1, '')\n    fs.chmodSync(f1, 0o666)\n    fs.chownSync(f1, process.getuid(), gidWheel)\n    const f1stats = fs.lstatSync(f1)\n    assert.strictEqual(f1stats.mode - S_IFREG, 0o666)\n\n    const d1 = path.join(srcDir, 'somedir')\n    fs.mkdirSync(d1)\n    fs.chmodSync(d1, 0o777)\n    fs.chownSync(d1, process.getuid(), gidStaff)\n    const d1stats = fs.lstatSync(d1)\n    assert.strictEqual(d1stats.mode - S_IFDIR, 0o777)\n\n    const f2 = path.join(d1, 'f2.bin')\n    fs.writeFileSync(f2, '')\n    fs.chmodSync(f2, 0o777)\n    fs.chownSync(f2, process.getuid(), gidStaff)\n    const f2stats = fs.lstatSync(f2)\n    assert.strictEqual(f2stats.mode - S_IFREG, 0o777)\n\n    const d2 = path.join(srcDir, 'crazydir')\n    fs.mkdirSync(d2)\n    fs.chmodSync(d2, 0o444)\n    fs.chownSync(d2, process.getuid(), gidWheel)\n    const d2stats = fs.lstatSync(d2)\n    assert.strictEqual(d2stats.mode - S_IFDIR, 0o444)\n\n    const destDir = path.join(permDir, 'dest')\n    fse.copy(srcDir, destDir, err => {\n      assert.ifError(err)\n\n      const newf1stats = fs.lstatSync(path.join(permDir, 'dest/f1.txt'))\n      const newd1stats = fs.lstatSync(path.join(permDir, 'dest/somedir'))\n      const newf2stats = fs.lstatSync(path.join(permDir, 'dest/somedir/f2.bin'))\n      const newd2stats = fs.lstatSync(path.join(permDir, 'dest/crazydir'))\n\n      assert.strictEqual(newf1stats.mode, f1stats.mode)\n      assert.strictEqual(newd1stats.mode, d1stats.mode)\n      assert.strictEqual(newf2stats.mode, f2stats.mode)\n      assert.strictEqual(newd2stats.mode, d2stats.mode)\n\n      assert.strictEqual(newf1stats.gid, f1stats.gid)\n      assert.strictEqual(newd1stats.gid, d1stats.gid)\n      assert.strictEqual(newf2stats.gid, f2stats.gid)\n      assert.strictEqual(newd2stats.gid, d2stats.gid)\n\n      assert.strictEqual(newf1stats.uid, f1stats.uid)\n      assert.strictEqual(newd1stats.uid, d1stats.uid)\n      assert.strictEqual(newf2stats.uid, f2stats.uid)\n      assert.strictEqual(newd2stats.uid, d2stats.uid)\n\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-preserve-timestamp.test.js",
    "content": "'use strict'\n\nconst fs = require('../../')\nconst os = require('os')\nconst path = require('path')\nconst { copy } = require('../')\nconst utimesSync = require('../../util/utimes').utimesMillisSync\nconst assert = require('assert')\n\n/* global beforeEach, afterEach, describe, it */\n\nif (process.arch === 'ia32') console.warn('32 bit arch; skipping copy timestamp tests')\n\nconst describeIfPractical = process.arch === 'ia32' ? describe.skip : describe\n\ndescribeIfPractical('copy() - preserve timestamp', () => {\n  let TEST_DIR, SRC, DEST, FILES\n\n  function setupFixture (readonly) {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-preserve-timestamp')\n    SRC = path.join(TEST_DIR, 'src')\n    DEST = path.join(TEST_DIR, 'dest')\n    FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')]\n    const timestamp = Date.now() / 1000 - 5\n    FILES.forEach(f => {\n      const filePath = path.join(SRC, f)\n      fs.ensureFileSync(filePath)\n      // rewind timestamps to make sure that coarser OS timestamp resolution\n      // does not alter results\n      utimesSync(filePath, timestamp, timestamp)\n      if (readonly) {\n        fs.chmodSync(filePath, 0o444)\n      }\n    })\n  }\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when preserveTimestamps option is true', () => {\n    ;[\n      { subcase: 'writable', readonly: false },\n      { subcase: 'readonly', readonly: true }\n    ].forEach(params => {\n      describe(`>> with ${params.subcase} source files`, () => {\n        beforeEach(() => setupFixture(params.readonly))\n\n        it('should have the same timestamps on copy', done => {\n          copy(SRC, DEST, { preserveTimestamps: true }, (err) => {\n            if (err) return done(err)\n            FILES.forEach(testFile({ preserveTimestamps: true }))\n            done()\n          })\n        })\n      })\n    })\n  })\n\n  function testFile (options) {\n    return function (file) {\n      const a = path.join(SRC, file)\n      const b = path.join(DEST, file)\n      const fromStat = fs.statSync(a)\n      const toStat = fs.statSync(b)\n      if (options.preserveTimestamps) {\n        // Windows sub-second precision fixed: https://github.com/nodejs/io.js/issues/2069\n        assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'different mtime values')\n        assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime(), 'different atime values')\n      } else {\n        // the access time might actually be the same, so check only modification time\n        assert.notStrictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'same mtime values')\n      }\n    }\n  }\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-prevent-copying-identical.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ copy() - prevent copying identical files and dirs', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-prevent-copying-identical')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  it('should return an error if src and dest are the same', done => {\n    const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n    const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n    fs.ensureFileSync(fileSrc)\n\n    fs.copy(fileSrc, fileDest, err => {\n      assert.strictEqual(err.message, 'Source and destination must not be the same.')\n      done()\n    })\n  })\n\n  describe('dest with parent symlink', () => {\n    describe('first parent is symlink', () => {\n      it('should error when src is file', done => {\n        const src = path.join(TEST_DIR, 'a', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.copy(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n\n      it('should error when src is directory', done => {\n        const src = path.join(TEST_DIR, 'a', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.copy(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n    })\n\n    describe('nested dest', () => {\n      it('should error when src is file', done => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.copy(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n\n      it('should error when src is directory', done => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.copy(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n    })\n  })\n\n  // src is directory:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a directory', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error if dereference is true', done => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const subdir = path.join(TEST_DIR, 'src', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const oldlen = klawSync(src).length\n\n        fs.copy(src, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const newlen = klawSync(src).length\n          assert.strictEqual(newlen, oldlen)\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error', done => {\n        dest = path.join(TEST_DIR, 'dest')\n        fs.mkdirsSync(dest)\n        const subdir = path.join(TEST_DIR, 'dest', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'dir')\n\n        const oldlen = klawSync(dest).length\n\n        fs.copy(srcLink, dest, err => {\n          assert.ok(err)\n\n          // assert nothing copied\n          const newlen = klawSync(dest).length\n          assert.strictEqual(newlen, oldlen)\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, dest)\n          done()\n        })\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error src and dest are the same and dereference is true', done => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n\n        fs.copy(srcLink, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const srclenAfter = klawSync(srcLink).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const destlenAfter = klawSync(destLink).length\n          assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n          done()\n        })\n      })\n    })\n  })\n\n  // src is file:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a file', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error', done => {\n        src = path.join(TEST_DIR, 'src.txt')\n        fs.outputFileSync(src, 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        fs.copy(src, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          done()\n        })\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error if dereference is true', done => {\n        dest = path.join(TEST_DIR, 'dest', 'somefile.txt')\n        fs.outputFileSync(dest, 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'file')\n\n        fs.copy(srcLink, dest, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, dest)\n          assert(fs.readFileSync(link, 'utf8'), 'some data')\n          done()\n        })\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error src and dest are the same and dereferene is true', done => {\n        src = path.join(TEST_DIR, 'src', 'srcfile.txt')\n        fs.outputFileSync(src, 'src data')\n\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'file')\n\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        fs.copy(srcLink, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n          assert(fs.readFileSync(srcln, 'utf8'), 'src data')\n          assert(fs.readFileSync(destln, 'utf8'), 'src data')\n          done()\n        })\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-prevent-copying-into-itself.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\n// these files are used for all tests\nconst FILES = [\n  'file0.txt',\n  path.join('dir1', 'file1.txt'),\n  path.join('dir1', 'dir2', 'file2.txt'),\n  path.join('dir1', 'dir2', 'dir3', 'file3.txt')\n]\n\nconst dat0 = 'file0'\nconst dat1 = 'file1'\nconst dat2 = 'file2'\nconst dat3 = 'file3'\n\ndescribe('+ copy() - prevent copying into itself', () => {\n  let TEST_DIR, src\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-prevent-copying-into-itself')\n    src = path.join(TEST_DIR, 'src')\n    fs.mkdirpSync(src)\n\n    fs.outputFileSync(path.join(src, FILES[0]), dat0)\n    fs.outputFileSync(path.join(src, FILES[1]), dat1)\n    fs.outputFileSync(path.join(src, FILES[2]), dat2)\n    fs.outputFileSync(path.join(src, FILES[3]), dat3)\n    done()\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when source is a file', () => {\n    it('should copy the file successfully even if dest parent is a subdir of src', done => {\n      const srcFile = path.join(TEST_DIR, 'src', 'srcfile.txt')\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'destfile.txt')\n      fs.writeFileSync(srcFile, dat0)\n\n      fs.copy(srcFile, destFile, err => {\n        assert.ifError(err)\n\n        assert(fs.existsSync(destFile, 'file copied'))\n        const out = fs.readFileSync(destFile, 'utf8')\n        assert.strictEqual(out, dat0, 'file contents matched')\n        done()\n      })\n    })\n  })\n\n  // test for these cases:\n  //  - src is directory, dest is directory\n  //  - src is directory, dest is symlink\n  //  - src is symlink, dest is directory\n  //  - src is symlink, dest is symlink\n\n  describe('> when source is a directory', () => {\n    describe('>> when dest is a directory', () => {\n      it('of not itself', done => {\n        const dest = path.join(TEST_DIR, src.replace(/^\\w:/, ''))\n        return testSuccess(src, dest, done)\n      })\n      it('of itself', done => {\n        const dest = path.join(src, 'dest')\n        return testError(src, dest, done)\n      })\n      it(\"should copy the directory successfully when dest is 'src_dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src_dest')\n        return testSuccess(src, dest, done)\n      })\n      it(\"should copy the directory successfully when dest is 'src-dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src-dest')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'dest_src'\", done => {\n        const dest = path.join(TEST_DIR, 'dest_src')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src_dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'src_dest', 'src')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src-dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'src-dest', 'src')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'dest_src/src'\", done => {\n        const dest = path.join(TEST_DIR, 'dest_src', 'src')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src_src/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src-src/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src-src', 'dest')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'srcsrc/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should copy the directory successfully when dest is 'dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'dest', 'src')\n        return testSuccess(src, dest, done)\n      })\n\n      it('should copy the directory successfully when dest is very nested that all its parents need to be created', done => {\n        const dest = path.join(TEST_DIR, 'dest', 'src', 'foo', 'bar', 'baz', 'qux', 'quux', 'waldo',\n          'grault', 'garply', 'fred', 'plugh', 'thud', 'some', 'highly', 'deeply',\n          'badly', 'nasty', 'crazy', 'mad', 'nested', 'dest')\n        return testSuccess(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'dest')\n        return testError(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/src_dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'src_dest')\n        return testError(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/dest_src'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'dest_src')\n        return testError(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'dest', 'src')\n        return testError(src, dest, done)\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when dest points exactly to src and dereference is true', done => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        fs.copy(src, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should error when dest is a subdirectory of src (bind-mounted directory with subdirectory)', done => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1')\n        assert(fs.existsSync(dest))\n        fs.copy(src, dest, err => {\n          assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)\n\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should error when dest is a subdirectory of src (more than one level depth)', done => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1', 'dir2')\n        assert(fs.existsSync(dest))\n        fs.copy(src, dest, err => {\n          assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${path.join(destLink, 'dir1')}'.`)\n\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should copy the directory successfully when src is a subdir of resolved dest path and dereference is true', done => {\n        const srcInDest = path.join(TEST_DIR, 'dest', 'some', 'nested', 'src')\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.copySync(src, srcInDest) // put some stuff in srcInDest\n\n        const dest = path.join(TEST_DIR, 'dest')\n        fs.symlinkSync(dest, destLink, 'dir')\n\n        const srclen = klawSync(srcInDest).length\n        const destlenBefore = klawSync(dest).length\n\n        assert(srclen > 2)\n        fs.copy(srcInDest, destLink, { dereference: true }, err => {\n          assert.ifError(err)\n\n          const destlenAfter = klawSync(dest).length\n\n          // assert dest length is oldlen + length of stuff copied from src\n          assert.strictEqual(destlenAfter, destlenBefore + srclen, 'dest length should be equal to old length + copied legnth')\n\n          FILES.forEach(f => assert(fs.existsSync(path.join(dest, f)), 'file copied'))\n\n          const o0 = fs.readFileSync(path.join(dest, FILES[0]), 'utf8')\n          const o1 = fs.readFileSync(path.join(dest, FILES[1]), 'utf8')\n          const o2 = fs.readFileSync(path.join(dest, FILES[2]), 'utf8')\n          const o3 = fs.readFileSync(path.join(dest, FILES[3]), 'utf8')\n\n          assert.strictEqual(o0, dat0, 'files contents matched')\n          assert.strictEqual(o1, dat1, 'files contents matched')\n          assert.strictEqual(o2, dat2, 'files contents matched')\n          assert.strictEqual(o3, dat3, 'files contents matched')\n          done()\n        })\n      })\n    })\n  })\n\n  describe('> when source is a symlink', () => {\n    describe('>> when dest is a directory', () => {\n      it('should error when resolved src path points to dest', done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src')\n\n        fs.copy(srcLink, dest, err => {\n          assert(err)\n          // assert source not affected\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should error when dest is a subdir of resolved src path', done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src', 'some', 'nested', 'dest')\n        fs.mkdirsSync(dest)\n\n        fs.copy(srcLink, dest, err => {\n          assert(err)\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should error when resolved src path is a subdir of dest', done => {\n        const dest = path.join(TEST_DIR, 'dest')\n\n        const resolvedSrcPath = path.join(dest, 'contains', 'src')\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.copySync(src, resolvedSrcPath)\n\n        // make symlink that points to a subdir in dest\n        fs.symlinkSync(resolvedSrcPath, srcLink, 'dir')\n\n        fs.copy(srcLink, dest, err => {\n          assert(err)\n          done()\n        })\n      })\n\n      it(\"should copy the directory successfully when dest is 'src_src/dest'\", done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        testSuccess(srcLink, dest, () => {\n          const link = fs.readlinkSync(dest)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it(\"should copy the directory successfully when dest is 'srcsrc/dest'\", done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        testSuccess(srcLink, dest, () => {\n          const link = fs.readlinkSync(dest)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when resolved dest path is exactly the same as resolved src path and dereference is true', done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n        assert(srclenBefore > 2)\n        assert(destlenBefore > 2)\n\n        fs.copy(srcLink, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const srclenAfter = klawSync(srcLink).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const destlenAfter = klawSync(destLink).length\n          assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n          done()\n        })\n      })\n\n      it('should error when resolved dest path is a subdir of resolved src path', done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        const resolvedDestPath = path.join(TEST_DIR, 'src', 'some', 'nested', 'dest')\n        fs.ensureFileSync(path.join(resolvedDestPath, 'subdir', 'somefile.txt'))\n        fs.symlinkSync(resolvedDestPath, destLink, 'dir')\n\n        fs.copy(srcLink, destLink, err => {\n          assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${resolvedDestPath}'.`)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, resolvedDestPath)\n          done()\n        })\n      })\n    })\n  })\n})\n\nfunction testSuccess (src, dest, done) {\n  const srclen = klawSync(src).length\n  assert(srclen > 2)\n  fs.copy(src, dest, err => {\n    assert.ifError(err)\n\n    FILES.forEach(f => assert(fs.existsSync(path.join(dest, f)), 'file copied'))\n\n    const o0 = fs.readFileSync(path.join(dest, FILES[0]), 'utf8')\n    const o1 = fs.readFileSync(path.join(dest, FILES[1]), 'utf8')\n    const o2 = fs.readFileSync(path.join(dest, FILES[2]), 'utf8')\n    const o3 = fs.readFileSync(path.join(dest, FILES[3]), 'utf8')\n\n    assert.strictEqual(o0, dat0, 'file contents matched')\n    assert.strictEqual(o1, dat1, 'file contents matched')\n    assert.strictEqual(o2, dat2, 'file contents matched')\n    assert.strictEqual(o3, dat3, 'file contents matched')\n    done()\n  })\n}\n\nfunction testError (src, dest, done) {\n  fs.copy(src, dest, err => {\n    assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)\n    done()\n  })\n}\n"
  },
  {
    "path": "lib/copy/__tests__/copy-readonly-dir.test.js",
    "content": "'use strict'\n\n// relevant: https://github.com/jprichardson/node-fs-extra/issues/599\n\nconst fs = require('../../')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\nconst klawSync = require('klaw-sync')\n\n/* global afterEach, beforeEach, describe, it */\n\nlet TEST_DIR = ''\n\nconst FILES = [\n  path.join('dir1', 'file1.txt'),\n  path.join('dir1', 'dir2', 'file2.txt'),\n  path.join('dir1', 'dir2', 'dir3', 'file3.txt')\n]\n\ndescribe('+ copy() - copy a readonly directory with content', () => {\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'test', 'fs-extra', 'copy-readonly-dir')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => {\n    klawSync(TEST_DIR).forEach(data => fs.chmodSync(data.path, 0o777))\n    fse.remove(TEST_DIR, done)\n  })\n\n  describe('> when src is readonly directory with content', () => {\n    it('should copy successfully', done => {\n      FILES.forEach(file => {\n        fs.outputFileSync(path.join(TEST_DIR, file), file)\n      })\n\n      const sourceDir = path.join(TEST_DIR, 'dir1')\n      const sourceHierarchy = klawSync(sourceDir)\n      sourceHierarchy.forEach(source => fs.chmodSync(source.path, source.stats.isDirectory() ? 0o555 : 0o444))\n\n      const targetDir = path.join(TEST_DIR, 'target')\n      fse.copy(sourceDir, targetDir, err => {\n        assert.ifError(err)\n\n        // Make sure copy was made and mode was preserved\n        assert(fs.existsSync(targetDir))\n        const targetHierarchy = klawSync(targetDir)\n        assert(targetHierarchy.length === sourceHierarchy.length)\n        targetHierarchy.forEach(target => assert(target.stats.mode === target.stats.isDirectory() ? 0o555 : 0o444))\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-symlink-same-target.test.js",
    "content": "'use strict'\n\nconst os = require('os')\nconst fs = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('copy() / symlink same target', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-symlink-same-target')\n\n  beforeEach(done => {\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => {\n    fs.remove(TEST_DIR, done)\n  })\n\n  describe('> when copying directory containing symlink', () => {\n    it('should copy symlink when dest has no existing symlink', done => {\n      const target = path.join(TEST_DIR, 'target')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.writeFileSync(path.join(target, 'file.txt'), 'content')\n      fs.mkdirpSync(src)\n      fs.symlinkSync(target, path.join(src, 'link'), 'dir')\n\n      // Copy\n      fs.copy(src, dest, err => {\n        assert.ifError(err)\n\n        // Verify symlink was copied\n        const destLink = path.join(dest, 'link')\n        assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n        assert.strictEqual(fs.readlinkSync(destLink), target)\n        done()\n      })\n    })\n\n    // Also tests issue #1027\n    it('should overwrite symlink when dest has existing symlink pointing to SAME target', done => {\n      const target = path.join(TEST_DIR, 'target')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.writeFileSync(path.join(target, 'file.txt'), 'content')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create symlinks pointing to the same target\n      fs.symlinkSync(target, path.join(src, 'link'), 'dir')\n      fs.symlinkSync(target, path.join(dest, 'link'), 'dir')\n\n      // Copy should work - two different symlinks pointing to same target are NOT the same file\n      fs.copy(src, dest)\n        .then(() => {\n          // Verify symlink was copied/overwritten\n          const destLink = path.join(dest, 'link')\n          assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n          assert.strictEqual(fs.readlinkSync(destLink), target)\n          done()\n        })\n        .catch(done)\n    })\n\n    it('should overwrite symlink when dest has existing symlink pointing to DIFFERENT target', done => {\n      const target1 = path.join(TEST_DIR, 'target1')\n      const target2 = path.join(TEST_DIR, 'target2')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.mkdirpSync(target1)\n      fs.mkdirpSync(target2)\n      fs.writeFileSync(path.join(target1, 'file.txt'), 'content1')\n      fs.writeFileSync(path.join(target2, 'file.txt'), 'content2')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create symlinks pointing to different targets\n      fs.symlinkSync(target1, path.join(src, 'link'), 'dir')\n      fs.symlinkSync(target2, path.join(dest, 'link'), 'dir')\n\n      // Copy should work\n      fs.copy(src, dest, err => {\n        assert.ifError(err)\n\n        // Verify symlink was copied/overwritten to point to target1\n        const destLink = path.join(dest, 'link')\n        assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n        assert.strictEqual(fs.readlinkSync(destLink), target1)\n        done()\n      })\n    })\n  })\n\n  describe('> when copying file symlinks', () => {\n    it('should overwrite file symlink when dest has existing symlink pointing to SAME target', done => {\n      const target = path.join(TEST_DIR, 'target.txt')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.writeFileSync(target, 'content')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create file symlinks pointing to the same target\n      fs.symlinkSync(target, path.join(src, 'link'), 'file')\n      fs.symlinkSync(target, path.join(dest, 'link'), 'file')\n\n      // Copy should work\n      fs.copy(src, dest)\n        .then(() => {\n          // Verify symlink was copied/overwritten\n          const destLink = path.join(dest, 'link')\n          assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n          assert.strictEqual(fs.readlinkSync(destLink), target)\n          done()\n        })\n        .catch(done)\n    })\n\n    it('should overwrite file symlink when dest has existing symlink pointing to DIFFERENT target', done => {\n      const target1 = path.join(TEST_DIR, 'target1.txt')\n      const target2 = path.join(TEST_DIR, 'target2.txt')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.writeFileSync(target1, 'content1')\n      fs.writeFileSync(target2, 'content2')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create file symlinks pointing to different targets\n      fs.symlinkSync(target1, path.join(src, 'link'), 'file')\n      fs.symlinkSync(target2, path.join(dest, 'link'), 'file')\n\n      // Copy should work\n      fs.copy(src, dest, err => {\n        assert.ifError(err)\n\n        // Verify symlink was copied/overwritten to point to target1\n        const destLink = path.join(dest, 'link')\n        assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n        assert.strictEqual(fs.readlinkSync(destLink), target1)\n        done()\n      })\n    })\n  })\n\n  describe('> when copying symlink directly to another symlink (issue #1019)', () => {\n    it('should copy symlink to another symlink pointing to same target', done => {\n      const target = path.join(TEST_DIR, 'target.txt')\n      const srcLink = path.join(TEST_DIR, 'srcLink')\n      const destLink = path.join(TEST_DIR, 'destLink')\n\n      // Setup - two different symlinks pointing to the same file\n      fs.writeFileSync(target, 'content')\n      fs.symlinkSync(target, srcLink, 'file')\n      fs.symlinkSync(target, destLink, 'file')\n\n      // Copy should work - these are different symlinks even though they point to the same target\n      fs.copy(srcLink, destLink)\n        .then(() => {\n          assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n          assert.strictEqual(fs.readlinkSync(destLink), target)\n          done()\n        })\n        .catch(done)\n    })\n  })\n\n  describe('> edge cases', () => {\n    it('should still prevent copying a symlink to itself', done => {\n      const target = path.join(TEST_DIR, 'target')\n      const link = path.join(TEST_DIR, 'link')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.symlinkSync(target, link, 'dir')\n\n      // Copying a symlink to itself should fail\n      fs.copy(link, link)\n        .then(() => {\n          done(new Error('Expected error to be thrown'))\n        })\n        .catch(err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          done()\n        })\n    })\n\n    it('should allow copying symlink to subdirectory of its target (symlink copy, not recursive)', done => {\n      // When copying a symlink (not dereferencing), we just copy the link itself\n      // This should be allowed because we're not recursively copying the target's contents\n      const target = path.join(TEST_DIR, 'target')\n      const src = path.join(TEST_DIR, 'src')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.mkdirpSync(path.join(target, 'subdir'))\n      fs.mkdirpSync(src)\n      fs.symlinkSync(target, path.join(src, 'link'), 'dir')\n\n      // Dest is inside src's resolved target\n      const dest = path.join(target, 'subdir', 'dest')\n\n      // This should work - we're just copying the symlink, not following it\n      fs.copy(src, dest)\n        .then(() => {\n          // Verify symlink was copied\n          const destLink = path.join(dest, 'link')\n          assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n          assert.strictEqual(fs.readlinkSync(destLink), target)\n          done()\n        })\n        .catch(done)\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-broken-symlink.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst copySync = require('../copy-sync')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('copy-sync / broken symlink', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-broken-symlink')\n  const src = path.join(TEST_DIR, 'src')\n  const dest = path.join(TEST_DIR, 'dest')\n\n  beforeEach(done => {\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n      createFixtures(src, done)\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('when symlink is broken', () => {\n    it('should not throw error if dereference is false', () => {\n      let err = null\n      try {\n        copySync(src, dest)\n      } catch (e) {\n        err = e\n      }\n      assert.strictEqual(err, null)\n    })\n\n    it('should throw error if dereference is true', () => {\n      assert.throws(() => copySync(src, dest, { dereference: true }), err => err.code === 'ENOENT')\n    })\n  })\n})\n\nfunction createFixtures (srcDir, callback) {\n  fs.mkdir(srcDir, err => {\n    let brokenFile\n    let brokenFileLink\n\n    if (err) return callback(err)\n\n    try {\n      brokenFile = path.join(srcDir, 'does-not-exist')\n      brokenFileLink = path.join(srcDir, 'broken-symlink')\n      fs.writeFileSync(brokenFile, 'does not matter')\n      fs.symlinkSync(brokenFile, brokenFileLink, 'file')\n    } catch (err) {\n      callback(err)\n    }\n\n    // break the symlink now\n    fse.remove(brokenFile, callback)\n  })\n}\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-case-insensitive-paths.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst platform = os.platform()\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ copySync() - case insensitive paths', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-case-insensitive-paths')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(() => fs.removeSync(TEST_DIR))\n\n  describe('> when src is a directory', () => {\n    it('should behave correctly based on the OS', () => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      dest = path.join(TEST_DIR, 'srcDir')\n      let errThrown = false\n\n      try {\n        fs.copySync(src, dest)\n      } catch (err) {\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          errThrown = true\n        }\n      }\n      if (platform === 'darwin' || platform === 'win32') assert(errThrown)\n      if (platform === 'linux') {\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n        assert(!errThrown)\n      }\n    })\n  })\n\n  describe('> when src is a file', () => {\n    it('should behave correctly based on the OS', () => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      dest = path.join(TEST_DIR, 'srcFile')\n      let errThrown = false\n\n      try {\n        fs.copySync(src, dest)\n      } catch (err) {\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          errThrown = true\n        }\n      }\n      if (platform === 'darwin' || platform === 'win32') assert(errThrown)\n      if (platform === 'linux') {\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n        assert(!errThrown)\n      }\n    })\n  })\n\n  describe('> when src is a symlink', () => {\n    it('should behave correctly based on the OS, symlink dir', () => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'dir')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n      let errThrown = false\n\n      try {\n        fs.copySync(srcLink, dest)\n      } catch (err) {\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          errThrown = true\n        }\n      }\n      if (platform === 'darwin' || platform === 'win32') assert(errThrown)\n      if (platform === 'linux') {\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n        const destLink = fs.readlinkSync(dest)\n        assert.strictEqual(destLink, src)\n        assert(!errThrown)\n      }\n    })\n\n    it('should behave correctly based on the OS, symlink file', () => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'file')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n      let errThrown = false\n\n      try {\n        fs.copySync(srcLink, dest)\n      } catch (err) {\n        if (platform === 'darwin' || platform === 'win32') {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          errThrown = true\n        }\n      }\n      if (platform === 'darwin' || platform === 'win32') assert(errThrown)\n      if (platform === 'linux') {\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n        const destLink = fs.readlinkSync(dest)\n        assert.strictEqual(destLink, src)\n        assert(!errThrown)\n      }\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-dir.test.js",
    "content": "'use strict'\n\nconst fs = require('../../')\nconst os = require('os')\nconst path = require('path')\nconst assert = require('assert')\nconst crypto = require('crypto')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ copySync() / dir', () => {\n  const SIZE = 16 * 64 * 1024 + 7\n  let TEST_DIR\n  let src, dest\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-dir')\n    src = path.join(TEST_DIR, 'src')\n    dest = path.join(TEST_DIR, 'dest')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when src is a directory', () => {\n    describe('> when dest exists and is a file', () => {\n      it('should throw error', () => {\n        const src = path.join(TEST_DIR, 'src')\n        const dest = path.join(TEST_DIR, 'file.txt')\n        fs.mkdirSync(src)\n        fs.ensureFileSync(dest)\n\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot overwrite non-directory '${dest}' with directory '${src}'.`)\n        }\n      })\n    })\n\n    it('should copy the directory synchronously', () => {\n      const FILES = 2\n\n      src = path.join(TEST_DIR, 'src')\n      dest = path.join(TEST_DIR, 'dest')\n\n      fs.mkdirSync(src)\n\n      for (let i = 0; i < FILES; ++i) {\n        fs.writeFileSync(path.join(src, i.toString()), crypto.randomBytes(SIZE))\n      }\n\n      const subdir = path.join(src, 'subdir')\n\n      fs.mkdirSync(subdir)\n\n      for (let i = 0; i < FILES; ++i) {\n        fs.writeFileSync(path.join(subdir, i.toString()), crypto.randomBytes(SIZE))\n      }\n\n      fs.copySync(src, dest)\n      assert(fs.existsSync(dest))\n\n      for (let i = 0; i < FILES; ++i) {\n        assert(fs.existsSync(path.join(dest, i.toString())))\n      }\n\n      const destSub = path.join(dest, 'subdir')\n      for (let j = 0; j < FILES; ++j) {\n        assert(fs.existsSync(path.join(destSub, j.toString())))\n      }\n    })\n\n    it('should preserve symbolic links', () => {\n      const srcTarget = path.join(TEST_DIR, 'destination')\n      fs.mkdirSync(src)\n      fs.mkdirSync(srcTarget)\n      fs.symlinkSync(srcTarget, path.join(src, 'symlink'), 'dir')\n\n      fs.copySync(src, dest)\n\n      const link = fs.readlinkSync(path.join(dest, 'symlink'))\n      assert.strictEqual(link, srcTarget)\n    })\n\n    describe('> when the destination dir does not exist', () => {\n      it('should create the destination directory and copy the file', () => {\n        const src = path.join(TEST_DIR, 'data/')\n        fs.mkdirSync(src)\n\n        const d1 = 'file1'\n        const d2 = 'file2'\n\n        fs.writeFileSync(path.join(src, 'f1.txt'), d1)\n        fs.writeFileSync(path.join(src, 'f2.txt'), d2)\n\n        const dest = path.join(TEST_DIR, 'this/path/does/not/exist/outputDir')\n\n        fs.copySync(src, dest)\n\n        const o1 = fs.readFileSync(path.join(dest, 'f1.txt'), 'utf8')\n        const o2 = fs.readFileSync(path.join(dest, 'f2.txt'), 'utf8')\n\n        assert.strictEqual(d1, o1)\n        assert.strictEqual(d2, o2)\n      })\n    })\n  })\n\n  describe('> when filter is used', () => {\n    it('should do nothing if filter fails', () => {\n      const srcDir = path.join(TEST_DIR, 'src')\n      const srcFile = path.join(srcDir, 'srcfile.css')\n      fs.outputFileSync(srcFile, 'src contents')\n      const destDir = path.join(TEST_DIR, 'dest')\n      const destFile = path.join(destDir, 'destfile.css')\n      const filter = s => path.extname(s) !== '.css' && !fs.statSync(s).isDirectory()\n\n      fs.copySync(srcFile, destFile, filter)\n      assert(!fs.existsSync(destDir))\n    })\n\n    it('should apply filter recursively', () => {\n      const FILES = 2\n      // Don't match anything that ends with a digit higher than 0:\n      const filter = s => /(0|\\D)$/i.test(s)\n\n      fs.mkdirSync(src)\n\n      for (let i = 0; i < FILES; ++i) {\n        fs.writeFileSync(path.join(src, i.toString()), crypto.randomBytes(SIZE))\n      }\n\n      const subdir = path.join(src, 'subdir')\n      fs.mkdirSync(subdir)\n\n      for (let i = 0; i < FILES; ++i) {\n        fs.writeFileSync(path.join(subdir, i.toString()), crypto.randomBytes(SIZE))\n      }\n\n      fs.copySync(src, dest, filter)\n\n      assert(fs.existsSync(dest))\n      assert(FILES > 1)\n\n      for (let i = 0; i < FILES; ++i) {\n        if (i === 0) {\n          assert(fs.existsSync(path.join(dest, i.toString())))\n        } else {\n          assert(!fs.existsSync(path.join(dest, i.toString())))\n        }\n      }\n\n      const destSub = path.join(dest, 'subdir')\n\n      for (let j = 0; j < FILES; ++j) {\n        if (j === 0) {\n          assert(fs.existsSync(path.join(destSub, j.toString())))\n        } else {\n          assert(!fs.existsSync(path.join(destSub, j.toString())))\n        }\n      }\n    })\n\n    it('should apply the filter to directory names', () => {\n      const IGNORE = 'ignore'\n      const filter = p => !~p.indexOf(IGNORE)\n\n      fs.mkdirSync(src)\n\n      const ignoreDir = path.join(src, IGNORE)\n      fs.mkdirSync(ignoreDir)\n\n      fs.writeFileSync(path.join(ignoreDir, 'file'), crypto.randomBytes(SIZE))\n\n      fs.copySync(src, dest, filter)\n\n      assert(!fs.existsSync(path.join(dest, IGNORE)), 'directory was not ignored')\n      assert(!fs.existsSync(path.join(dest, IGNORE, 'file')), 'file was not ignored')\n    })\n\n    it('should apply filter when it is applied only to dest', done => {\n      const timeCond = new Date().getTime()\n\n      const filter = (s, d) => fs.statSync(d).mtime.getTime() < timeCond\n\n      const dest = path.join(TEST_DIR, 'dest')\n\n      setTimeout(() => {\n        fs.outputFileSync(path.join(src, 'somefile.html'), 'some data')\n        fs.mkdirSync(dest)\n        fs.copySync(src, dest, filter)\n        assert(!fs.existsSync(path.join(dest, 'somefile.html')))\n        done()\n      }, 1000)\n    })\n\n    it('should apply filter when it is applied to both src and dest', done => {\n      const timeCond = new Date().getTime()\n      const filter = (s, d) => s.split('.').pop() !== 'css' && fs.statSync(path.dirname(d)).mtime.getTime() > timeCond\n\n      const dest = path.join(TEST_DIR, 'dest')\n\n      setTimeout(() => {\n        const srcFile1 = path.join(TEST_DIR, '1.html')\n        const srcFile2 = path.join(TEST_DIR, '2.css')\n        const srcFile3 = path.join(TEST_DIR, '3.jade')\n\n        fs.writeFileSync(srcFile1, '')\n        fs.writeFileSync(srcFile2, '')\n        fs.writeFileSync(srcFile3, '')\n\n        const destFile1 = path.join(dest, 'dest1.html')\n        const destFile2 = path.join(dest, 'dest2.css')\n        const destFile3 = path.join(dest, 'dest3.jade')\n\n        fs.mkdirSync(dest)\n\n        fs.copySync(srcFile1, destFile1, filter)\n        fs.copySync(srcFile2, destFile2, filter)\n        fs.copySync(srcFile3, destFile3, filter)\n\n        assert(fs.existsSync(destFile1))\n        assert(!fs.existsSync(destFile2))\n        assert(fs.existsSync(destFile3))\n        done()\n      }, 1000)\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-file.test.js",
    "content": "'use strict'\n\nconst fs = require('../../')\nconst os = require('os')\nconst path = require('path')\nconst assert = require('assert')\nconst crypto = require('crypto')\n\n/* global afterEach, beforeEach, describe, it */\n\nconst SIZE = 16 * 64 * 1024 + 7\n\ndescribe('+ copySync() / file', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-file')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when src is a file', () => {\n    describe('> when dest exists and is a directory', () => {\n      it('should throw error', () => {\n        const src = path.join(TEST_DIR, 'file.txt')\n        const dest = path.join(TEST_DIR, 'dir')\n        fs.ensureFileSync(src)\n        fs.ensureDirSync(dest)\n\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot overwrite directory '${dest}' with non-directory '${src}'.`)\n        }\n      })\n    })\n\n    it('should copy the file synchronously', () => {\n      const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')\n      const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n\n      fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE))\n\n      const srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex')\n      let destMd5 = ''\n\n      fs.copySync(fileSrc, fileDest)\n\n      destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest('hex')\n      assert.strictEqual(srcMd5, destMd5)\n    })\n\n    it('should follow symlinks', () => {\n      const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')\n      const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n      const linkSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy_link')\n\n      fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE))\n\n      const srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex')\n      let destMd5 = ''\n\n      fs.symlinkSync(fileSrc, linkSrc)\n      fs.copySync(linkSrc, fileDest)\n      destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest('hex')\n      assert.strictEqual(srcMd5, destMd5)\n    })\n\n    it('should maintain file mode', () => {\n      const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')\n      const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n      fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE))\n\n      fs.chmodSync(fileSrc, 0o750)\n      fs.copySync(fileSrc, fileDest)\n\n      const statSrc = fs.statSync(fileSrc)\n      const statDest = fs.statSync(fileDest)\n      assert.strictEqual(statSrc.mode, statDest.mode)\n    })\n\n    it('should only copy files allowed by filter fn', () => {\n      const srcFile1 = path.join(TEST_DIR, '1.html')\n      const srcFile2 = path.join(TEST_DIR, '2.css')\n      const srcFile3 = path.join(TEST_DIR, '3.jade')\n\n      fs.writeFileSync(srcFile1, '')\n      fs.writeFileSync(srcFile2, '')\n      fs.writeFileSync(srcFile3, '')\n\n      const destFile1 = path.join(TEST_DIR, 'dest1.html')\n      const destFile2 = path.join(TEST_DIR, 'dest2.css')\n      const destFile3 = path.join(TEST_DIR, 'dest3.jade')\n\n      const filter = s => s.split('.').pop() !== 'css'\n\n      fs.copySync(srcFile1, destFile1, filter)\n      fs.copySync(srcFile2, destFile2, filter)\n      fs.copySync(srcFile3, destFile3, filter)\n\n      assert(fs.existsSync(destFile1))\n      assert(!fs.existsSync(destFile2))\n      assert(fs.existsSync(destFile3))\n    })\n\n    it('should not call filter fn more than needed', () => {\n      const src = path.join(TEST_DIR, 'foo')\n\n      fs.writeFileSync(src, '')\n\n      const dest = path.join(TEST_DIR, 'bar')\n\n      let filterCallCount = 0\n      const filter = () => {\n        filterCallCount++\n        return true\n      }\n\n      fs.copySync(src, dest, filter)\n\n      assert.strictEqual(filterCallCount, 1)\n      assert(fs.existsSync(dest))\n    })\n\n    describe('> when the destination dir does not exist', () => {\n      it('should create the destination directory and copy the file', () => {\n        const src = path.join(TEST_DIR, 'file.txt')\n        const dest = path.join(TEST_DIR, 'this/path/does/not/exist/copied.txt')\n        const data = 'did it copy?\\n'\n\n        fs.writeFileSync(src, data, 'utf8')\n        fs.copySync(src, dest)\n\n        const data2 = fs.readFileSync(dest, 'utf8')\n\n        assert.strictEqual(data, data2)\n      })\n    })\n\n    describe('> when src file does not have write permissions', () => {\n      it('should be able to copy contents of file', () => {\n        const fileSrc = path.join(TEST_DIR, 'file.txt')\n        const fileDest = path.join(TEST_DIR, 'file-copy.txt')\n        const data = 'did it copy?'\n\n        fs.writeFileSync(fileSrc, data, 'utf8')\n        fs.chmodSync(fileSrc, '0444')\n\n        fs.copySync(fileSrc, fileDest)\n\n        const data2 = fs.readFileSync(fileDest, 'utf8')\n\n        assert.strictEqual(data, data2)\n      })\n    })\n\n    describe('> when overwrite option is passed', () => {\n      const srcData = 'some src data'\n      let src, dest\n\n      beforeEach(() => {\n        src = path.join(TEST_DIR, 'src-file')\n        dest = path.join(TEST_DIR, 'des-file')\n\n        // source file must always exist in these cases\n        fs.writeFileSync(src, srcData)\n      })\n\n      describe('> when destination file does NOT exist', () => {\n        describe('> when overwrite is true', () => {\n          it('should copy the file and not throw an error', () => {\n            fs.copySync(src, dest, { overwrite: true })\n            const destData = fs.readFileSync(dest, 'utf8')\n            assert.strictEqual(srcData, destData)\n          })\n        })\n\n        describe('> when overwrite is false', () => {\n          it('should copy the file and not throw an error', () => {\n            fs.copySync(src, dest, { overwrite: false })\n            const destData = fs.readFileSync(dest, 'utf8')\n            assert.strictEqual(srcData, destData)\n          })\n        })\n      })\n\n      describe('when destination file does exist', () => {\n        let destData\n\n        beforeEach(() => {\n          destData = 'some dest data'\n          fs.writeFileSync(dest, destData)\n        })\n\n        describe('> when overwrite is true', () => {\n          it('should copy the file and not throw an error', () => {\n            fs.copySync(src, dest, { overwrite: true })\n            destData = fs.readFileSync(dest, 'utf8')\n            assert.strictEqual(srcData, destData)\n          })\n        })\n\n        describe('> when overwrite is false', () => {\n          it('should not throw an error', () => {\n            fs.copySync(src, dest, { overwrite: false })\n\n            // copy never happened\n            const destDataNew = fs.readFileSync(dest, 'utf8')\n            assert.strictEqual(destData, destDataNew)\n          })\n          it('should throw an error when errorOnExist is true', () => {\n            assert.throws(() => fs.copySync(src, dest, { overwrite: false, errorOnExist: true }))\n\n            // copy never happened\n            const destDataNew = fs.readFileSync(dest, 'utf8')\n            assert.strictEqual(destData, destDataNew)\n          })\n        })\n\n        describe('> when overwrite is true and dest is readonly', () => {\n          it('should copy the file and not throw an error', () => {\n            try {\n              fs.chmodSync(dest, 0o444)\n              fs.copySync(src, dest, { overwrite: true })\n              destData = fs.readFileSync(dest, 'utf8')\n              assert.strictEqual(srcData, destData)\n            } finally {\n              // destination file is readonly so just remove it so we don't affect other tests\n              fs.unlinkSync(dest)\n            }\n          })\n        })\n      })\n    })\n    describe('clobber', () => {\n      let src, dest, srcData, destData\n\n      beforeEach(() => {\n        src = path.join(TEST_DIR, 'src-file')\n        dest = path.join(TEST_DIR, 'des-file')\n        srcData = 'some src data'\n        destData = 'some dest data'\n        fs.writeFileSync(src, srcData)\n        fs.writeFileSync(dest, destData)\n      })\n\n      it('is an alias for overwrite', () => {\n        fs.copySync(src, dest, { clobber: false })\n\n        // copy never happened\n        const destDataNew = fs.readFileSync(dest, 'utf8')\n        assert.strictEqual(destData, destDataNew)\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-preserve-timestamp.test.js",
    "content": "'use strict'\n\nconst fs = require('../../')\nconst os = require('os')\nconst path = require('path')\nconst copySync = require('../copy-sync')\nconst utimesSync = require('../../util/utimes').utimesMillisSync\nconst assert = require('assert')\n\n/* global beforeEach, afterEach, describe, it */\n\nif (process.arch === 'ia32') console.warn('32 bit arch; skipping copySync timestamp tests')\n\nconst describeIfPractical = process.arch === 'ia32' ? describe.skip : describe\n\ndescribeIfPractical('copySync() - preserveTimestamps option', () => {\n  let TEST_DIR, SRC, DEST, FILES\n\n  function setupFixture (readonly) {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-preserve-timestamp')\n    SRC = path.join(TEST_DIR, 'src')\n    DEST = path.join(TEST_DIR, 'dest')\n    FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')]\n    const timestamp = Date.now() / 1000 - 5\n    FILES.forEach(f => {\n      const filePath = path.join(SRC, f)\n      fs.ensureFileSync(filePath)\n      // rewind timestamps to make sure that coarser OS timestamp resolution\n      // does not alter results\n      utimesSync(filePath, timestamp, timestamp)\n      if (readonly) {\n        fs.chmodSync(filePath, 0o444)\n      }\n    })\n  }\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when preserveTimestamps option is true', () => {\n    ;[\n      { subcase: 'writable', readonly: false },\n      { subcase: 'readonly', readonly: true }\n    ].forEach(params => {\n      describe(`>> with ${params.subcase} source files`, () => {\n        beforeEach(() => setupFixture(params.readonly))\n\n        it('should have the same timestamps on copy', () => {\n          copySync(SRC, DEST, { preserveTimestamps: true })\n          FILES.forEach(testFile({ preserveTimestamps: true }))\n        })\n      })\n    })\n  })\n\n  function testFile (options) {\n    return function (file) {\n      const a = path.join(SRC, file)\n      const b = path.join(DEST, file)\n      const fromStat = fs.statSync(a)\n      const toStat = fs.statSync(b)\n      if (options.preserveTimestamps) {\n        // Windows sub-second precision fixed: https://github.com/nodejs/io.js/issues/2069\n        assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'different mtime values')\n        assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime(), 'different atime values')\n      } else {\n        // the access time might actually be the same, so check only modification time\n        assert.notStrictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'same mtime values')\n      }\n    }\n  }\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-prevent-copying-identical.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ copySync() - prevent copying identical files and dirs', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-prevent-copying-identical')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  it('should return an error if src and dest are the same', () => {\n    const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy_sync')\n    const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy_sync')\n    fs.ensureFileSync(fileSrc)\n\n    try {\n      fs.copySync(fileSrc, fileDest)\n    } catch (err) {\n      assert.strictEqual(err.message, 'Source and destination must not be the same.')\n    }\n  })\n\n  describe('dest with parent symlink', () => {\n    describe('first parent is symlink', () => {\n      it('should error when src is file', () => {\n        const src = path.join(TEST_DIR, 'a', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n\n      it('should error when src is directory', () => {\n        const src = path.join(TEST_DIR, 'a', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n    })\n\n    describe('nested dest', () => {\n      it('should error when src is file', () => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n\n      it('should error when src is directory', () => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n    })\n  })\n\n  // src is directory:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a directory', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error if dereference is true', () => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const subdir = path.join(TEST_DIR, 'src', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const oldlen = klawSync(src).length\n\n        try {\n          fs.copySync(src, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const newlen = klawSync(src).length\n        assert.strictEqual(newlen, oldlen)\n        const link = fs.readlinkSync(destLink)\n        assert.strictEqual(link, src)\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error', () => {\n        dest = path.join(TEST_DIR, 'dest')\n        fs.mkdirsSync(dest)\n        const subdir = path.join(TEST_DIR, 'dest', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'dir')\n\n        const oldlen = klawSync(dest).length\n\n        try {\n          fs.copySync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n        }\n\n        // assert nothing copied\n        const newlen = klawSync(dest).length\n        assert.strictEqual(newlen, oldlen)\n        const link = fs.readlinkSync(srcLink)\n        assert.strictEqual(link, dest)\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error if src and dest are the same and dereferene is true', () => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n\n        try {\n          fs.copySync(srcLink, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const srclenAfter = klawSync(srcLink).length\n        assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n        const destlenAfter = klawSync(destLink).length\n        assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n        const srcln = fs.readlinkSync(srcLink)\n        assert.strictEqual(srcln, src)\n        const destln = fs.readlinkSync(destLink)\n        assert.strictEqual(destln, src)\n      })\n    })\n  })\n\n  // src is file:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a file', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error if dereference is true', () => {\n        src = path.join(TEST_DIR, 'src', 'somefile.txt')\n        fs.ensureFileSync(src)\n        fs.writeFileSync(src, 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        try {\n          fs.copySync(src, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const link = fs.readlinkSync(destLink)\n        assert.strictEqual(link, src)\n        assert(fs.readFileSync(link, 'utf8'), 'some data')\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error', () => {\n        dest = path.join(TEST_DIR, 'dest', 'somefile.txt')\n        fs.outputFileSync(dest, 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'file')\n\n        try {\n          fs.copySync(srcLink, dest)\n        } catch (err) {\n          assert.ok(err)\n        }\n        const link = fs.readlinkSync(srcLink)\n        assert.strictEqual(link, dest)\n        assert(fs.readFileSync(link, 'utf8'), 'some data')\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error if src and dest are the same and dereference is true', () => {\n        src = path.join(TEST_DIR, 'src', 'srcfile.txt')\n        fs.outputFileSync(src, 'src data')\n\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'file')\n\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        try {\n          fs.copySync(srcLink, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const srcln = fs.readlinkSync(srcLink)\n        assert.strictEqual(srcln, src)\n        const destln = fs.readlinkSync(destLink)\n        assert.strictEqual(destln, src)\n        assert(fs.readFileSync(srcln, 'utf8'), 'src data')\n        assert(fs.readFileSync(destln, 'utf8'), 'src data')\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-prevent-copying-into-itself.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\n// these files are used for all tests\nconst FILES = [\n  'file0.txt',\n  path.join('dir1', 'file1.txt'),\n  path.join('dir1', 'dir2', 'file2.txt'),\n  path.join('dir1', 'dir2', 'dir3', 'file3.txt')\n]\n\nconst dat0 = 'file0'\nconst dat1 = 'file1'\nconst dat2 = 'file2'\nconst dat3 = 'file3'\n\ndescribe('+ copySync() - prevent copying into itself', () => {\n  let TEST_DIR, src\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-prevent-copying-into-itself')\n    src = path.join(TEST_DIR, 'src')\n    fs.mkdirpSync(src)\n\n    fs.outputFileSync(path.join(src, FILES[0]), dat0)\n    fs.outputFileSync(path.join(src, FILES[1]), dat1)\n    fs.outputFileSync(path.join(src, FILES[2]), dat2)\n    fs.outputFileSync(path.join(src, FILES[3]), dat3)\n    done()\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when source is a file', () => {\n    it('should copy the file successfully even if dest parent is a subdir of src', () => {\n      const srcFile = path.join(TEST_DIR, 'src', 'srcfile.txt')\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'destfile.txt')\n      fs.writeFileSync(srcFile, dat0)\n\n      fs.copySync(srcFile, destFile)\n\n      assert(fs.existsSync(destFile, 'file copied'))\n      const out = fs.readFileSync(destFile, 'utf8')\n      assert.strictEqual(out, dat0, 'file contents matched')\n    })\n  })\n\n  // test for these cases:\n  //  - src is directory, dest is directory\n  //  - src is directory, dest is symlink\n  //  - src is symlink, dest is directory\n  //  - src is symlink, dest is symlink\n\n  describe('> when source is a directory', () => {\n    describe('>> when dest is a directory', () => {\n      it('of not itself', () => {\n        const dest = path.join(TEST_DIR, src.replace(/^\\w:/, ''))\n        return testSuccess(src, dest)\n      })\n      it('of itself', () => {\n        const dest = path.join(src, 'dest')\n        return testError(src, dest)\n      })\n      it(\"should copy the directory successfully when dest is 'src_dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src_dest')\n        return testSuccess(src, dest)\n      })\n      it(\"should copy the directory successfully when dest is 'src-dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src-dest')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'dest_src'\", () => {\n        const dest = path.join(TEST_DIR, 'dest_src')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src_dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'src_dest', 'src')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src-dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'src-dest', 'src')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'dest_src/src'\", () => {\n        const dest = path.join(TEST_DIR, 'dest_src', 'src')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src_src/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'src-src/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src-src', 'dest')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'srcsrc/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should copy the directory successfully when dest is 'dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'dest', 'src')\n        return testSuccess(src, dest)\n      })\n\n      it('should copy the directory successfully when dest is very nested that all its parents need to be created', () => {\n        const dest = path.join(TEST_DIR, 'dest', 'src', 'foo', 'bar', 'baz', 'qux', 'quux', 'waldo',\n          'grault', 'garply', 'fred', 'plugh', 'thud', 'some', 'highly', 'deeply',\n          'badly', 'nasty', 'crazy', 'mad', 'nested', 'dest')\n        return testSuccess(src, dest)\n      })\n\n      it(\"should error when dest is 'src/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'dest')\n        return testError(src, dest)\n      })\n\n      it(\"should error when dest is 'src/src_dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'src_dest')\n        return testError(src, dest)\n      })\n\n      it(\"should error when dest is 'src/dest_src'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'dest_src')\n        return testError(src, dest)\n      })\n\n      it(\"should error when dest is 'src/dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'dest', 'src')\n        return testError(src, dest)\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when dest points exactly to src and dereference is true', () => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        try {\n          fs.copySync(src, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const srclenAfter = klawSync(src).length\n        assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n        const link = fs.readlinkSync(destLink)\n        assert.strictEqual(link, src)\n      })\n\n      it('should error when dest is a subdirectory of src (bind-mounted directory with subdirectory)', () => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1')\n        assert(fs.existsSync(dest))\n        let errThrown = false\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n        }\n      })\n\n      it('should error when dest is a subdirectory of src (more than one level depth)', () => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1', 'dir2')\n        assert(fs.existsSync(dest))\n        let errThrown = false\n        try {\n          fs.copySync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${path.join(destLink, 'dir1')}'.`)\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n        }\n      })\n\n      it('should copy the directory successfully when src is a subdir of resolved dest path and dereferene is true', () => {\n        const srcInDest = path.join(TEST_DIR, 'dest', 'some', 'nested', 'src')\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.copySync(src, srcInDest) // put some stuff in srcInDest\n\n        const dest = path.join(TEST_DIR, 'dest')\n        fs.symlinkSync(dest, destLink, 'dir')\n\n        const srclen = klawSync(srcInDest).length\n        const destlenBefore = klawSync(dest).length\n        assert(srclen > 2)\n\n        fs.copySync(srcInDest, destLink, { dereference: true })\n\n        const destlenAfter = klawSync(dest).length\n\n        // assert dest length is oldlen + length of stuff copied from src\n        assert.strictEqual(destlenAfter, destlenBefore + srclen, 'dest length should be equal to old length + copied legnth')\n\n        FILES.forEach(f => assert(fs.existsSync(path.join(dest, f)), 'file copied'))\n\n        const o0 = fs.readFileSync(path.join(dest, FILES[0]), 'utf8')\n        const o1 = fs.readFileSync(path.join(dest, FILES[1]), 'utf8')\n        const o2 = fs.readFileSync(path.join(dest, FILES[2]), 'utf8')\n        const o3 = fs.readFileSync(path.join(dest, FILES[3]), 'utf8')\n\n        assert.strictEqual(o0, dat0, 'files contents matched')\n        assert.strictEqual(o1, dat1, 'files contents matched')\n        assert.strictEqual(o2, dat2, 'files contents matched')\n        assert.strictEqual(o3, dat3, 'files contents matched')\n      })\n    })\n  })\n\n  describe('> when source is a symlink', () => {\n    describe('>> when dest is a directory', () => {\n      it('should error when resolved src path points to dest', () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src')\n\n        try {\n          fs.copySync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n        }\n        // assert source not affected\n        const link = fs.readlinkSync(srcLink)\n        assert.strictEqual(link, src)\n      })\n\n      it('should error when dest is a subdir of resolved src path', () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src', 'some', 'nested', 'dest')\n        fs.mkdirsSync(dest)\n\n        try {\n          fs.copySync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n        }\n        const link = fs.readlinkSync(srcLink)\n        assert.strictEqual(link, src)\n      })\n\n      it('should error when resolved src path is a subdir of dest', () => {\n        const dest = path.join(TEST_DIR, 'dest')\n\n        const resolvedSrcPath = path.join(dest, 'contains', 'src')\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.copySync(src, resolvedSrcPath)\n\n        // make symlink that points to a subdir in dest\n        fs.symlinkSync(resolvedSrcPath, srcLink, 'dir')\n\n        try {\n          fs.copySync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n        }\n      })\n\n      it(\"should copy the directory successfully when dest is 'src_src/dest'\", () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        testSuccess(srcLink, dest)\n        const link = fs.readlinkSync(dest)\n        assert.strictEqual(link, src)\n      })\n\n      it(\"should copy the directory successfully when dest is 'srcsrc/dest'\", () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        testSuccess(srcLink, dest)\n        const link = fs.readlinkSync(dest)\n        assert.strictEqual(link, src)\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when resolved dest path is exactly the same as resolved src path and dereference is true', () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n        assert(srclenBefore > 2)\n        assert(destlenBefore > 2)\n\n        try {\n          fs.copySync(srcLink, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          const srclenAfter = klawSync(srcLink).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const destlenAfter = klawSync(destLink).length\n          assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n        }\n      })\n\n      it('should error when resolved dest path is a subdir of resolved src path', () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        const resolvedDestPath = path.join(TEST_DIR, 'src', 'some', 'nested', 'dest')\n        fs.ensureFileSync(path.join(resolvedDestPath, 'subdir', 'somefile.txt'))\n\n        fs.symlinkSync(resolvedDestPath, destLink, 'dir')\n\n        try {\n          fs.copySync(srcLink, destLink)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${resolvedDestPath}'.`)\n        } finally {\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, resolvedDestPath)\n        }\n      })\n\n      it('should error when resolved src path is a subdir of resolved dest path', () => {\n        const srcInDest = path.join(TEST_DIR, 'dest', 'some', 'nested', 'src')\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n\n        const dest = path.join(TEST_DIR, 'dest')\n\n        fs.ensureDirSync(srcInDest)\n        fs.ensureSymlinkSync(srcInDest, srcLink, 'dir')\n        fs.ensureSymlinkSync(dest, destLink, 'dir')\n\n        try {\n          fs.copySync(srcLink, destLink)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot overwrite '${dest}' with '${srcInDest}'.`)\n        } finally {\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, dest)\n        }\n      })\n    })\n  })\n})\n\nfunction testSuccess (src, dest) {\n  const srclen = klawSync(src).length\n  assert(srclen > 2)\n\n  fs.copySync(src, dest)\n\n  FILES.forEach(f => assert(fs.existsSync(path.join(dest, f)), 'file copied'))\n\n  const o0 = fs.readFileSync(path.join(dest, FILES[0]), 'utf8')\n  const o1 = fs.readFileSync(path.join(dest, FILES[1]), 'utf8')\n  const o2 = fs.readFileSync(path.join(dest, FILES[2]), 'utf8')\n  const o3 = fs.readFileSync(path.join(dest, FILES[3]), 'utf8')\n\n  assert.strictEqual(o0, dat0, 'file contents matched')\n  assert.strictEqual(o1, dat1, 'file contents matched')\n  assert.strictEqual(o2, dat2, 'file contents matched')\n  assert.strictEqual(o3, dat3, 'file contents matched')\n}\n\nfunction testError (src, dest) {\n  try {\n    fs.copySync(src, dest)\n  } catch (err) {\n    assert.strictEqual(err.message, `Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)\n  }\n}\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-readonly-dir.test.js",
    "content": "'use strict'\n\n// relevant: https://github.com/jprichardson/node-fs-extra/issues/599\n\nconst os = require('os')\nconst fs = require('../../')\nconst path = require('path')\nconst assert = require('assert')\nconst klawSync = require('klaw-sync')\n\n/* global afterEach, beforeEach, describe, it */\n\nlet TEST_DIR = ''\n\nconst FILES = [\n  path.join('dir1', 'file1.txt'),\n  path.join('dir1', 'dir2', 'file2.txt'),\n  path.join('dir1', 'dir2', 'dir3', 'file3.txt')\n]\n\ndescribe('+ copySync() - copy a readonly directory with content', () => {\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'test', 'fs-extra', 'copy-readonly-dir')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => {\n    klawSync(TEST_DIR).forEach(data => fs.chmodSync(data.path, 0o777))\n    fs.remove(TEST_DIR, done)\n  })\n\n  describe('> when src is readonly directory with content', () => {\n    it('should copy successfully', () => {\n      FILES.forEach(file => {\n        fs.outputFileSync(path.join(TEST_DIR, file), file)\n      })\n      const sourceDir = path.join(TEST_DIR, 'dir1')\n      const sourceHierarchy = klawSync(sourceDir)\n      sourceHierarchy.forEach(source => fs.chmodSync(source.path, source.stats.isDirectory() ? 0o555 : 0o444))\n\n      const targetDir = path.join(TEST_DIR, 'target')\n      fs.copySync(sourceDir, targetDir)\n\n      // Make sure copy was made and mode was preserved\n      assert(fs.existsSync(targetDir))\n      const targetHierarchy = klawSync(targetDir)\n      assert(targetHierarchy.length === sourceHierarchy.length)\n      targetHierarchy.forEach(target => assert(target.stats.mode === target.stats.isDirectory() ? 0o555 : 0o444))\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-symlink-same-target.test.js",
    "content": "'use strict'\n\nconst os = require('os')\nconst fs = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst copySync = require('../copy-sync')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('copy-sync / symlink same target', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-symlink-same-target')\n\n  beforeEach(done => {\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => {\n    fs.remove(TEST_DIR, done)\n  })\n\n  describe('> when copying directory containing symlink', () => {\n    it('should copy symlink when dest has no existing symlink', () => {\n      const target = path.join(TEST_DIR, 'target')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.writeFileSync(path.join(target, 'file.txt'), 'content')\n      fs.mkdirpSync(src)\n      fs.symlinkSync(target, path.join(src, 'link'), 'dir')\n\n      // Copy\n      assert.doesNotThrow(() => {\n        copySync(src, dest)\n      })\n\n      // Verify symlink was copied\n      const destLink = path.join(dest, 'link')\n      assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n      assert.strictEqual(fs.readlinkSync(destLink), target)\n    })\n\n    // Also tests issue #1027\n    it('should overwrite symlink when dest has existing symlink pointing to SAME target', () => {\n      const target = path.join(TEST_DIR, 'target')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.writeFileSync(path.join(target, 'file.txt'), 'content')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create symlinks pointing to the same target\n      fs.symlinkSync(target, path.join(src, 'link'), 'dir')\n      fs.symlinkSync(target, path.join(dest, 'link'), 'dir')\n\n      // Copy should work - two different symlinks pointing to same target are NOT the same file\n      assert.doesNotThrow(() => {\n        copySync(src, dest)\n      })\n\n      // Verify symlink was copied/overwritten\n      const destLink = path.join(dest, 'link')\n      assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n      assert.strictEqual(fs.readlinkSync(destLink), target)\n    })\n\n    it('should overwrite symlink when dest has existing symlink pointing to DIFFERENT target', () => {\n      const target1 = path.join(TEST_DIR, 'target1')\n      const target2 = path.join(TEST_DIR, 'target2')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.mkdirpSync(target1)\n      fs.mkdirpSync(target2)\n      fs.writeFileSync(path.join(target1, 'file.txt'), 'content1')\n      fs.writeFileSync(path.join(target2, 'file.txt'), 'content2')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create symlinks pointing to different targets\n      fs.symlinkSync(target1, path.join(src, 'link'), 'dir')\n      fs.symlinkSync(target2, path.join(dest, 'link'), 'dir')\n\n      // Copy should work\n      assert.doesNotThrow(() => {\n        copySync(src, dest)\n      })\n\n      // Verify symlink was copied/overwritten to point to target1\n      const destLink = path.join(dest, 'link')\n      assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n      assert.strictEqual(fs.readlinkSync(destLink), target1)\n    })\n  })\n\n  describe('> when copying file symlinks', () => {\n    it('should overwrite file symlink when dest has existing symlink pointing to SAME target', () => {\n      const target = path.join(TEST_DIR, 'target.txt')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.writeFileSync(target, 'content')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create file symlinks pointing to the same target\n      fs.symlinkSync(target, path.join(src, 'link'), 'file')\n      fs.symlinkSync(target, path.join(dest, 'link'), 'file')\n\n      // Copy should work\n      assert.doesNotThrow(() => {\n        copySync(src, dest)\n      })\n\n      // Verify symlink was copied/overwritten\n      const destLink = path.join(dest, 'link')\n      assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n      assert.strictEqual(fs.readlinkSync(destLink), target)\n    })\n\n    it('should overwrite file symlink when dest has existing symlink pointing to DIFFERENT target', () => {\n      const target1 = path.join(TEST_DIR, 'target1.txt')\n      const target2 = path.join(TEST_DIR, 'target2.txt')\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n\n      // Setup\n      fs.writeFileSync(target1, 'content1')\n      fs.writeFileSync(target2, 'content2')\n      fs.mkdirpSync(src)\n      fs.mkdirpSync(dest)\n      // Create file symlinks pointing to different targets\n      fs.symlinkSync(target1, path.join(src, 'link'), 'file')\n      fs.symlinkSync(target2, path.join(dest, 'link'), 'file')\n\n      // Copy should work\n      assert.doesNotThrow(() => {\n        copySync(src, dest)\n      })\n\n      // Verify symlink was copied/overwritten to point to target1\n      const destLink = path.join(dest, 'link')\n      assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n      assert.strictEqual(fs.readlinkSync(destLink), target1)\n    })\n  })\n\n  describe('> when copying symlink directly to another symlink (issue #1019)', () => {\n    it('should copy symlink to another symlink pointing to same target', () => {\n      const target = path.join(TEST_DIR, 'target.txt')\n      const srcLink = path.join(TEST_DIR, 'srcLink')\n      const destLink = path.join(TEST_DIR, 'destLink')\n\n      // Setup - two different symlinks pointing to the same file\n      fs.writeFileSync(target, 'content')\n      fs.symlinkSync(target, srcLink, 'file')\n      fs.symlinkSync(target, destLink, 'file')\n\n      // Copy should work - these are different symlinks even though they point to the same target\n      assert.doesNotThrow(() => {\n        copySync(srcLink, destLink)\n      })\n\n      assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n      assert.strictEqual(fs.readlinkSync(destLink), target)\n    })\n  })\n\n  describe('> edge cases', () => {\n    it('should still prevent copying a symlink to itself', () => {\n      const target = path.join(TEST_DIR, 'target')\n      const link = path.join(TEST_DIR, 'link')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.symlinkSync(target, link, 'dir')\n\n      // Copying a symlink to itself should fail\n      assert.throws(() => {\n        copySync(link, link)\n      }, /Source and destination must not be the same/)\n    })\n\n    it('should allow copying symlink to subdirectory of its target (symlink copy, not recursive)', () => {\n      // When copying a symlink (not dereferencing), we just copy the link itself\n      // This should be allowed because we're not recursively copying the target's contents\n      const target = path.join(TEST_DIR, 'target')\n      const src = path.join(TEST_DIR, 'src')\n\n      // Setup\n      fs.mkdirpSync(target)\n      fs.mkdirpSync(path.join(target, 'subdir'))\n      fs.mkdirpSync(src)\n      fs.symlinkSync(target, path.join(src, 'link'), 'dir')\n\n      // Dest is inside src's resolved target\n      const dest = path.join(target, 'subdir', 'dest')\n\n      // This should work - we're just copying the symlink, not following it\n      assert.doesNotThrow(() => {\n        copySync(src, dest)\n      })\n\n      // Verify symlink was copied\n      const destLink = path.join(dest, 'link')\n      assert.ok(fs.lstatSync(destLink).isSymbolicLink())\n      assert.strictEqual(fs.readlinkSync(destLink), target)\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/copy-sync-symlink.test.js",
    "content": "'use strict'\n\nconst os = require('os')\nconst fs = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst copySync = require('../copy-sync')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('copy-sync / symlink', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-symlinks')\n  const src = path.join(TEST_DIR, 'src')\n  const out = path.join(TEST_DIR, 'out')\n\n  beforeEach(done => {\n    fs.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n      createFixtures(src, done)\n    })\n  })\n\n  afterEach(done => {\n    fs.remove(TEST_DIR, done)\n  })\n\n  it('copies symlinks by default', () => {\n    assert.doesNotThrow(() => {\n      copySync(src, out)\n    })\n\n    assert.strictEqual(fs.readlinkSync(path.join(out, 'file-symlink')), path.join(src, 'foo'))\n    assert.strictEqual(fs.readlinkSync(path.join(out, 'dir-symlink')), path.join(src, 'dir'))\n  })\n\n  it('copies file contents when dereference=true', () => {\n    try {\n      copySync(src, out, { dereference: true })\n    } catch (err) {\n      assert.ifError(err)\n    }\n\n    const fileSymlinkPath = path.join(out, 'file-symlink')\n    assert.ok(fs.lstatSync(fileSymlinkPath).isFile())\n    assert.strictEqual(fs.readFileSync(fileSymlinkPath, 'utf8'), 'foo contents')\n\n    const dirSymlinkPath = path.join(out, 'dir-symlink')\n    assert.ok(fs.lstatSync(dirSymlinkPath).isDirectory())\n    assert.deepStrictEqual(fs.readdirSync(dirSymlinkPath), ['bar'])\n  })\n})\n\nfunction createFixtures (srcDir, callback) {\n  fs.mkdir(srcDir, err => {\n    if (err) return callback(err)\n\n    // note: third parameter in symlinkSync is type e.g. 'file' or 'dir'\n    // https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback\n    try {\n      const fooFile = path.join(srcDir, 'foo')\n      const fooFileLink = path.join(srcDir, 'file-symlink')\n      fs.writeFileSync(fooFile, 'foo contents')\n      fs.symlinkSync(fooFile, fooFileLink, 'file')\n\n      const dir = path.join(srcDir, 'dir')\n      const dirFile = path.join(dir, 'bar')\n      const dirLink = path.join(srcDir, 'dir-symlink')\n      fs.mkdirSync(dir)\n      fs.writeFileSync(dirFile, 'bar contents')\n      fs.symlinkSync(dir, dirLink, 'dir')\n    } catch (err) {\n      callback(err)\n    }\n\n    callback()\n  })\n}\n"
  },
  {
    "path": "lib/copy/__tests__/copy.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\nconst crypto = require('crypto')\n\n/* global afterEach, beforeEach, describe, it */\n\nconst SIZE = 16 * 64 * 1024 + 7\nlet TEST_DIR = ''\n\ndescribe('fs-extra', () => {\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ copy()', () => {\n    it('should return an error if src and dest are the same', done => {\n      const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n      const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n      fse.ensureFileSync(fileSrc)\n\n      fse.copy(fileSrc, fileDest, err => {\n        assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        done()\n      })\n    })\n\n    it('should error when overwrite=false and file exists', done => {\n      const src = path.join(TEST_DIR, 'src.txt')\n      const dest = path.join(TEST_DIR, 'dest.txt')\n\n      fse.ensureFileSync(src)\n      fse.ensureFileSync(dest)\n      fse.copy(src, dest, { overwrite: false, errorOnExist: true }, err => {\n        assert(err)\n        done()\n      })\n    })\n\n    it('should error when overwrite=false and file exists in a dir', done => {\n      const src = path.join(TEST_DIR, 'src', 'sfile.txt')\n      const dest = path.join(TEST_DIR, 'dest', 'dfile.txt')\n\n      fse.ensureFileSync(src)\n      fse.ensureFileSync(dest)\n      fse.copy(src, dest, { overwrite: false, errorOnExist: true }, err => {\n        assert(err)\n        done()\n      })\n    })\n\n    describe('> when src is a file', () => {\n      it('should copy the file asynchronously', done => {\n        const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')\n        const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n        fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE))\n        const srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex')\n        let destMd5 = ''\n\n        fse.copy(fileSrc, fileDest, err => {\n          assert(!err)\n          destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest('hex')\n          assert.strictEqual(srcMd5, destMd5)\n          done()\n        })\n      })\n\n      it('should work with promises', () => {\n        const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')\n        const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n        fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE))\n        const srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex')\n        let destMd5 = ''\n\n        return fse.copy(fileSrc, fileDest).then(() => {\n          destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest('hex')\n          assert.strictEqual(srcMd5, destMd5)\n        })\n      })\n\n      it('should return an error if src file does not exist', done => {\n        const fileSrc = 'we-simply-assume-this-file-does-not-exist.bin'\n        const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy')\n\n        fse.copy(fileSrc, fileDest, err => {\n          assert(err)\n          done()\n        })\n      })\n\n      it('should copy to a destination file with two \\'$\\' characters in name (eg: TEST_fs-extra_$$_copy)', done => {\n        const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src')\n        const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_$$_copy')\n\n        fs.writeFileSync(fileSrc, '')\n\n        fse.copy(fileSrc, fileDest, err => {\n          assert(!err)\n          fs.statSync(fileDest)\n          done()\n        })\n      })\n\n      describe('> when the destination dir does not exist', () => {\n        it('should create the destination directory and copy the file', done => {\n          const src = path.join(TEST_DIR, 'file.txt')\n          const dest = path.join(TEST_DIR, 'this/path/does/not/exist/copied.txt')\n          const data = 'did it copy?\\n'\n\n          fs.writeFileSync(src, data, 'utf8')\n\n          fse.copy(src, dest, err => {\n            const data2 = fs.readFileSync(dest, 'utf8')\n            assert.strictEqual(data, data2)\n            done(err)\n          })\n        })\n      })\n\n      describe('> when dest exists and is a directory', () => {\n        it('should return an error', done => {\n          const src = path.join(TEST_DIR, 'file.txt')\n          const dest = path.join(TEST_DIR, 'dir')\n          fse.ensureFileSync(src)\n          fse.ensureDirSync(dest)\n\n          fse.copy(src, dest, err => {\n            assert.strictEqual(err.message, `Cannot overwrite directory '${dest}' with non-directory '${src}'.`)\n            done()\n          })\n        })\n      })\n    })\n\n    describe('> when src is a directory', () => {\n      describe('> when src directory does not exist', () => {\n        it('should return an error', done => {\n          const ts = path.join(TEST_DIR, 'this_dir_does_not_exist')\n          const td = path.join(TEST_DIR, 'this_dir_really_does_not_matter')\n          fse.copy(ts, td, err => {\n            assert(err)\n            done()\n          })\n        })\n      })\n\n      describe('> when dest exists and is a file', () => {\n        it('should return an error', done => {\n          const src = path.join(TEST_DIR, 'src')\n          const dest = path.join(TEST_DIR, 'file.txt')\n          fs.mkdirSync(src)\n          fse.ensureFileSync(dest)\n\n          fse.copy(src, dest, err => {\n            assert.strictEqual(err.message, `Cannot overwrite non-directory '${dest}' with directory '${src}'.`)\n            done()\n          })\n        })\n      })\n\n      it('should preserve symbolic links', done => {\n        const src = path.join(TEST_DIR, 'src')\n        const dest = path.join(TEST_DIR, 'dest')\n        const srcTarget = path.join(TEST_DIR, 'destination')\n        fse.mkdirSync(src)\n        fse.mkdirSync(srcTarget)\n        // symlink type is only used for Windows and the default is 'file'.\n        // https://nodejs.org/api/fs.html#fs_fs_symlink_target_path_type_callback\n        fse.symlinkSync(srcTarget, path.join(src, 'symlink'), 'dir')\n\n        fse.copy(src, dest, err => {\n          assert.ifError(err)\n          const link = fs.readlinkSync(path.join(dest, 'symlink'))\n          assert.strictEqual(link, srcTarget)\n          done()\n        })\n      })\n\n      it('should copy the directory asynchronously', done => {\n        const FILES = 2\n        const src = path.join(TEST_DIR, 'src')\n        const dest = path.join(TEST_DIR, 'dest')\n\n        fse.mkdirs(src, err => {\n          assert(!err)\n          for (let i = 0; i < FILES; ++i) {\n            fs.writeFileSync(path.join(src, i.toString()), crypto.randomBytes(SIZE))\n          }\n\n          const subdir = path.join(src, 'subdir')\n          fse.mkdirs(subdir, err => {\n            assert(!err)\n            for (let i = 0; i < FILES; ++i) {\n              fs.writeFileSync(path.join(subdir, i.toString()), crypto.randomBytes(SIZE))\n            }\n\n            fse.copy(src, dest, err => {\n              assert.ifError(err)\n              assert(fs.existsSync(dest))\n\n              for (let i = 0; i < FILES; ++i) {\n                assert(fs.existsSync(path.join(dest, i.toString())))\n              }\n\n              const destSub = path.join(dest, 'subdir')\n              for (let j = 0; j < FILES; ++j) {\n                assert(fs.existsSync(path.join(destSub, j.toString())))\n              }\n\n              done()\n            })\n          })\n        })\n      })\n\n      describe('> when the destination dir does not exist', () => {\n        it('should create the destination directory and copy the file', done => {\n          const src = path.join(TEST_DIR, 'data/')\n          fse.mkdirsSync(src)\n          const d1 = 'file1'\n          const d2 = 'file2'\n\n          fs.writeFileSync(path.join(src, 'f1.txt'), d1)\n          fs.writeFileSync(path.join(src, 'f2.txt'), d2)\n\n          const dest = path.join(TEST_DIR, 'this/path/does/not/exist/outputDir')\n\n          fse.copy(src, dest, err => {\n            const o1 = fs.readFileSync(path.join(dest, 'f1.txt'), 'utf8')\n            const o2 = fs.readFileSync(path.join(dest, 'f2.txt'), 'utf8')\n\n            assert.strictEqual(d1, o1)\n            assert.strictEqual(d2, o2)\n\n            done(err)\n          })\n        })\n      })\n\n      describe('> when src dir does not exist', () => {\n        it('should return an error', done => {\n          fse.copy('/does/not/exist', '/something/else', err => {\n            assert(err instanceof Error)\n            done()\n          })\n        })\n      })\n    })\n\n    describe('> when filter is used', () => {\n      it('should do nothing if filter fails', done => {\n        const srcDir = path.join(TEST_DIR, 'src')\n        const srcFile = path.join(srcDir, 'srcfile.css')\n        fse.outputFileSync(srcFile, 'src contents')\n        const destDir = path.join(TEST_DIR, 'dest')\n        const destFile = path.join(destDir, 'destfile.css')\n        const filter = s => path.extname(s) !== '.css' && !fs.statSync(s).isDirectory()\n\n        fse.copy(srcFile, destFile, filter, err => {\n          assert.ifError(err)\n          assert(!fs.existsSync(destDir))\n          done()\n        })\n      })\n\n      it('should only copy files allowed by filter fn', done => {\n        const srcFile1 = path.join(TEST_DIR, '1.css')\n        fs.writeFileSync(srcFile1, '')\n        const destFile1 = path.join(TEST_DIR, 'dest1.css')\n        const filter = s => s.split('.').pop() !== 'css'\n\n        fse.copy(srcFile1, destFile1, filter, err => {\n          assert(!err)\n          assert(!fs.existsSync(destFile1))\n          done()\n        })\n      })\n\n      it('should not call filter fn more than needed', done => {\n        const src = path.join(TEST_DIR, 'foo')\n        fs.writeFileSync(src, '')\n        const dest = path.join(TEST_DIR, 'bar')\n\n        let filterCallCount = 0\n        const filter = () => {\n          filterCallCount++\n          return true\n        }\n\n        fse.copy(src, dest, filter, err => {\n          assert(!err)\n          assert.strictEqual(filterCallCount, 1)\n          assert(fs.existsSync(dest))\n          done()\n        })\n      })\n\n      it('accepts options object in place of filter', done => {\n        const srcFile1 = path.join(TEST_DIR, '1.jade')\n        fs.writeFileSync(srcFile1, '')\n        const destFile1 = path.join(TEST_DIR, 'dest1.jade')\n        const options = { filter: s => /.html$|.css$/i.test(s) }\n\n        fse.copy(srcFile1, destFile1, options, (err) => {\n          assert(!err)\n          assert(!fs.existsSync(destFile1))\n          done()\n        })\n      })\n\n      it('allows filter fn to return a promise', done => {\n        const srcFile1 = path.join(TEST_DIR, '1.css')\n        fs.writeFileSync(srcFile1, '')\n        const destFile1 = path.join(TEST_DIR, 'dest1.css')\n        const filter = s => Promise.resolve(s.split('.').pop() !== 'css')\n\n        fse.copy(srcFile1, destFile1, filter, err => {\n          assert(!err)\n          assert(!fs.existsSync(destFile1))\n          done()\n        })\n      })\n\n      it('should apply filter recursively', done => {\n        const FILES = 2\n        // Don't match anything that ends with a digit higher than 0:\n        const filter = s => /(0|\\D)$/i.test(s)\n\n        const src = path.join(TEST_DIR, 'src')\n        fse.mkdirsSync(src)\n\n        for (let i = 0; i < FILES; ++i) {\n          fs.writeFileSync(path.join(src, i.toString()), crypto.randomBytes(SIZE))\n        }\n\n        const subdir = path.join(src, 'subdir')\n        fse.mkdirsSync(subdir)\n\n        for (let i = 0; i < FILES; ++i) {\n          fs.writeFileSync(path.join(subdir, i.toString()), crypto.randomBytes(SIZE))\n        }\n        const dest = path.join(TEST_DIR, 'dest')\n        fse.copy(src, dest, filter, err => {\n          assert(!err)\n\n          assert(fs.existsSync(dest))\n          assert(FILES > 1)\n\n          for (let i = 0; i < FILES; ++i) {\n            if (i === 0) {\n              assert(fs.existsSync(path.join(dest, i.toString())))\n            } else {\n              assert(!fs.existsSync(path.join(dest, i.toString())))\n            }\n          }\n\n          const destSub = path.join(dest, 'subdir')\n\n          for (let j = 0; j < FILES; ++j) {\n            if (j === 0) {\n              assert(fs.existsSync(path.join(destSub, j.toString())))\n            } else {\n              assert(!fs.existsSync(path.join(destSub, j.toString())))\n            }\n          }\n          done()\n        })\n      })\n\n      it('should apply filter to directory names', done => {\n        const IGNORE = 'ignore'\n        const filter = p => !~p.indexOf(IGNORE)\n\n        const src = path.join(TEST_DIR, 'src')\n        fse.mkdirsSync(src)\n\n        const ignoreDir = path.join(src, IGNORE)\n        fse.mkdirsSync(ignoreDir)\n\n        fse.writeFileSync(path.join(ignoreDir, 'file'), crypto.randomBytes(SIZE))\n\n        const dest = path.join(TEST_DIR, 'dest')\n\n        fse.copy(src, dest, filter, err => {\n          assert.ifError(err)\n          assert(!fs.existsSync(path.join(dest, IGNORE)), 'directory was not ignored')\n          assert(!fs.existsSync(path.join(dest, IGNORE, 'file')), 'file was not ignored')\n          done()\n        })\n      })\n\n      it('should apply filter when it is applied only to dest', done => {\n        const timeCond = new Date().getTime()\n\n        const filter = (s, d) => fs.statSync(d).mtime.getTime() < timeCond\n\n        const src = path.join(TEST_DIR, 'src')\n        fse.mkdirsSync(src)\n        const subdir = path.join(src, 'subdir')\n        fse.mkdirsSync(subdir)\n\n        const dest = path.join(TEST_DIR, 'dest')\n\n        setTimeout(() => {\n          fse.mkdirsSync(dest)\n\n          fse.copy(src, dest, filter, err => {\n            assert(!err)\n            assert(!fs.existsSync(path.join(dest, 'subdir')))\n            done()\n          })\n        }, 1000)\n      })\n\n      it('should apply filter when it is applied to both src and dest', done => {\n        const timeCond = new Date().getTime()\n        const filter = (s, d) => s.split('.').pop() !== 'css' && fs.statSync(path.dirname(d)).mtime.getTime() > timeCond\n\n        const dest = path.join(TEST_DIR, 'dest')\n        setTimeout(() => {\n          fse.mkdirsSync(dest)\n\n          const srcFile1 = path.join(TEST_DIR, '1.html')\n          const srcFile2 = path.join(TEST_DIR, '2.css')\n          const srcFile3 = path.join(TEST_DIR, '3.jade')\n\n          fse.writeFileSync(srcFile1, '')\n          fse.writeFileSync(srcFile2, '')\n          fse.writeFileSync(srcFile3, '')\n\n          const destFile1 = path.join(dest, 'dest1.html')\n          const destFile2 = path.join(dest, 'dest2.css')\n          const destFile3 = path.join(dest, 'dest3.jade')\n\n          fse.copy(srcFile1, destFile1, filter, err => {\n            assert(!err)\n            assert(fs.existsSync(destFile1))\n\n            fse.copy(srcFile2, destFile2, filter, err => {\n              assert(!err)\n              assert(!fs.existsSync(destFile2))\n\n              fse.copy(srcFile3, destFile3, filter, err => {\n                assert(!err)\n                assert(fs.existsSync(destFile3))\n                done()\n              })\n            })\n          })\n        }, 1000)\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/README.md",
    "content": "These tests came from: https://github.com/AvianFlu/ncp/tree/v1.0.1/test"
  },
  {
    "path": "lib/copy/__tests__/ncp/broken-symlink.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../..')\nconst { copy: ncp } = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('ncp broken symlink', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-broken-symlinks')\n  const src = path.join(TEST_DIR, 'src')\n  const out = path.join(TEST_DIR, 'out')\n\n  beforeEach(done => {\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n      createFixtures(src, done)\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('should not error if symlink is broken', done => {\n    ncp(src, out, err => {\n      assert.strictEqual(err, null)\n      done()\n    })\n  })\n\n  it('should return an error if symlink is broken and dereference=true', done => {\n    ncp(src, out, { dereference: true }, err => {\n      assert.strictEqual(err.code, 'ENOENT')\n      done()\n    })\n  })\n})\n\nfunction createFixtures (srcDir, callback) {\n  fs.mkdir(srcDir, err => {\n    let brokenFile\n    let brokenFileLink\n\n    if (err) return callback(err)\n\n    try {\n      brokenFile = path.join(srcDir, 'does-not-exist')\n      brokenFileLink = path.join(srcDir, 'broken-symlink')\n      fs.writeFileSync(brokenFile, 'does not matter')\n      fs.symlinkSync(brokenFile, brokenFileLink, 'file')\n    } catch (err) {\n      callback(err)\n    }\n\n    // break the symlink now\n    fse.remove(brokenFile, callback)\n  })\n}\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/modified-files/out/a",
    "content": "test2"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/modified-files/src/a",
    "content": "test3"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/a",
    "content": "Hello world\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/b",
    "content": "Hello ncp\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/c",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/d",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/e",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/f",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/sub/a",
    "content": "Hello nodejitsu\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/out/sub/b",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/a",
    "content": "Hello world\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/b",
    "content": "Hello ncp\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/c",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/d",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/e",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/f",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/sub/a",
    "content": "Hello nodejitsu\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/fixtures/regular-fixtures/src/sub/b",
    "content": ""
  },
  {
    "path": "lib/copy/__tests__/ncp/ncp-error-perm.test.js",
    "content": "'use strict'\n\n// file in reference: https://github.com/jprichardson/node-fs-extra/issues/56\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../..')\nconst { copy: ncp } = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\n// skip test for windows\n// eslint-disable globalReturn */\n// if (os.platform().indexOf('win') === 0) return\n// eslint-enable globalReturn */\n\ndescribe('ncp / error / dest-permission', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-error-dest-perm')\n  const src = path.join(TEST_DIR, 'src')\n  const dest = path.join(TEST_DIR, 'dest')\n\n  // when we are root, then we will be able to create the subdirectory even if\n  // we don't have the permissions to do so, so no point in running this test\n  if (os.platform().indexOf('win') === 0 || os.userInfo().uid === 0) return\n\n  beforeEach(done => {\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n      done()\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('should return an error', done => {\n    const someFile = path.join(src, 'some-file')\n    fse.outputFileSync(someFile, 'hello')\n\n    fse.mkdirsSync(dest)\n    fs.chmodSync(dest, 0o444)\n\n    const subdest = path.join(dest, 'another-dir')\n\n    ncp(src, subdest, err => {\n      assert(err)\n      assert.strictEqual(err.code, 'EACCES')\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/ncp.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst { copy: ncp } = require('../../')\nconst path = require('path')\nconst rimraf = require('rimraf')\nconst assert = require('assert')\nconst readDirFiles = require('read-dir-files').read // temporary, will remove\n\n/* eslint-env mocha */\n\nconst fixturesDir = path.join(__dirname, 'fixtures')\n\ndescribe('ncp', () => {\n  describe('regular files and directories', () => {\n    const fixtures = path.join(fixturesDir, 'regular-fixtures')\n    const src = path.join(fixtures, 'src')\n    const out = path.join(fixtures, 'out')\n\n    before(cb => rimraf(out, () => ncp(src, out, cb)))\n\n    describe('when copying a directory of files', () => {\n      it('files are copied correctly', cb => {\n        readDirFiles(src, 'utf8', (srcErr, srcFiles) => {\n          readDirFiles(out, 'utf8', (outErr, outFiles) => {\n            assert.ifError(srcErr)\n            assert.deepStrictEqual(srcFiles, outFiles)\n            cb()\n          })\n        })\n      })\n    })\n\n    describe('when copying files using filter', () => {\n      before(cb => {\n        const filter = name => name.slice(-1) !== 'a'\n\n        rimraf(out, () => ncp(src, out, { filter }, cb))\n      })\n\n      it('files are copied correctly', cb => {\n        readDirFiles(src, 'utf8', (srcErr, srcFiles) => {\n          function filter (files) {\n            for (const fileName in files) {\n              const curFile = files[fileName]\n              if (curFile instanceof Object) {\n                filter(curFile)\n              } else if (fileName.slice(-1) === 'a') {\n                delete files[fileName]\n              }\n            }\n          }\n          filter(srcFiles)\n          readDirFiles(out, 'utf8', (outErr, outFiles) => {\n            assert.ifError(outErr)\n            assert.deepStrictEqual(srcFiles, outFiles)\n            cb()\n          })\n        })\n      })\n    })\n\n    describe('when using overwrite=true', () => {\n      before(function () {\n        this.originalCreateReadStream = fs.createReadStream\n      })\n\n      after(function () {\n        fs.createReadStream = this.originalCreateReadStream\n      })\n\n      it('the copy is complete after callback', done => {\n        ncp(src, out, { overwrite: true }, err => {\n          fs.createReadStream = () => done(new Error('createReadStream after callback'))\n\n          assert.ifError(err)\n          process.nextTick(done)\n        })\n      })\n    })\n\n    describe('when using overwrite=false', () => {\n      beforeEach(done => rimraf(out, done))\n\n      it('works', cb => {\n        ncp(src, out, { overwrite: false }, err => {\n          assert.ifError(err)\n          cb()\n        })\n      })\n\n      it('should not error if files exist', cb => {\n        ncp(src, out, () => {\n          ncp(src, out, { overwrite: false }, err => {\n            assert.ifError(err)\n            cb()\n          })\n        })\n      })\n\n      it('should error if errorOnExist and file exists', cb => {\n        ncp(src, out, () => {\n          ncp(src, out, {\n            overwrite: false,\n            errorOnExist: true\n          }, err => {\n            assert(err)\n            cb()\n          })\n        })\n      })\n    })\n\n    describe('clobber', () => {\n      beforeEach(done => rimraf(out, done))\n\n      it('is an alias for overwrite', cb => {\n        ncp(src, out, () => {\n          ncp(src, out, {\n            clobber: false,\n            errorOnExist: true\n          }, err => {\n            assert(err)\n            cb()\n          })\n        })\n      })\n    })\n\n    describe('when using transform', () => {\n      it('file descriptors are passed correctly', cb => {\n        ncp(src, out, {\n          transform: (read, write, file) => {\n            assert.notStrictEqual(file.name, undefined)\n            assert.strictEqual(typeof file.mode, 'number')\n            read.pipe(write)\n          }\n        }, cb)\n      })\n    })\n  })\n\n  // see https://github.com/AvianFlu/ncp/issues/71\n  describe('Issue 71: Odd Async Behaviors', () => {\n    const fixtures = path.join(__dirname, 'fixtures', 'regular-fixtures')\n    const src = path.join(fixtures, 'src')\n    const out = path.join(fixtures, 'out')\n\n    let totalCallbacks = 0\n\n    function copyAssertAndCount (callback) {\n      // rimraf(out, function() {\n      ncp(src, out, err => {\n        assert(!err)\n        totalCallbacks += 1\n        readDirFiles(src, 'utf8', (srcErr, srcFiles) => {\n          readDirFiles(out, 'utf8', (outErr, outFiles) => {\n            assert.ifError(srcErr)\n            assert.deepStrictEqual(srcFiles, outFiles)\n            callback()\n          })\n        })\n      })\n      // })\n    }\n\n    describe('when copying a directory of files without cleaning the destination', () => {\n      it('callback fires once per run and directories are equal', done => {\n        const expected = 10\n        let count = 10\n\n        function next () {\n          if (count > 0) {\n            setTimeout(() => {\n              copyAssertAndCount(() => {\n                count -= 1\n                next()\n              })\n            }, 100)\n          } else {\n            // console.log('Total callback count is', totalCallbacks)\n            assert.strictEqual(totalCallbacks, expected)\n            done()\n          }\n        }\n\n        next()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/copy/__tests__/ncp/symlink.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../..')\nconst { copy: ncp } = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('ncp / symlink', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-symlinks')\n  const src = path.join(TEST_DIR, 'src')\n  const out = path.join(TEST_DIR, 'out')\n\n  beforeEach(done => {\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n      createFixtures(src, done)\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('copies symlinks by default', done => {\n    ncp(src, out, err => {\n      assert.ifError(err)\n\n      assert.strictEqual(fs.readlinkSync(path.join(out, 'file-symlink')), path.join(src, 'foo'))\n      assert.strictEqual(fs.readlinkSync(path.join(out, 'dir-symlink')), path.join(src, 'dir'))\n\n      done()\n    })\n  })\n\n  it('copies file contents when dereference=true', done => {\n    ncp(src, out, { dereference: true }, err => {\n      assert.ifError(err)\n\n      const fileSymlinkPath = path.join(out, 'file-symlink')\n      assert.ok(fs.lstatSync(fileSymlinkPath).isFile())\n      assert.strictEqual(fs.readFileSync(fileSymlinkPath, 'utf8'), 'foo contents')\n\n      const dirSymlinkPath = path.join(out, 'dir-symlink')\n      assert.ok(fs.lstatSync(dirSymlinkPath).isDirectory())\n      assert.deepStrictEqual(fs.readdirSync(dirSymlinkPath), ['bar'])\n\n      done()\n    })\n  })\n})\n\nfunction createFixtures (srcDir, callback) {\n  fs.mkdir(srcDir, err => {\n    if (err) return callback(err)\n\n    // note: third parameter in symlinkSync is type e.g. 'file' or 'dir'\n    // https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback\n    try {\n      const fooFile = path.join(srcDir, 'foo')\n      const fooFileLink = path.join(srcDir, 'file-symlink')\n      fs.writeFileSync(fooFile, 'foo contents')\n      fs.symlinkSync(fooFile, fooFileLink, 'file')\n\n      const dir = path.join(srcDir, 'dir')\n      const dirFile = path.join(dir, 'bar')\n      const dirLink = path.join(srcDir, 'dir-symlink')\n      fs.mkdirSync(dir)\n      fs.writeFileSync(dirFile, 'bar contents')\n      fs.symlinkSync(dir, dirLink, 'dir')\n    } catch (err) {\n      callback(err)\n    }\n\n    callback()\n  })\n}\n"
  },
  {
    "path": "lib/copy/copy-sync.js",
    "content": "'use strict'\n\nconst fs = require('graceful-fs')\nconst path = require('path')\nconst mkdirsSync = require('../mkdirs').mkdirsSync\nconst utimesMillisSync = require('../util/utimes').utimesMillisSync\nconst stat = require('../util/stat')\n\nfunction copySync (src, dest, opts) {\n  if (typeof opts === 'function') {\n    opts = { filter: opts }\n  }\n\n  opts = opts || {}\n  opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now\n  opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber\n\n  // Warn about using preserveTimestamps on 32-bit node\n  if (opts.preserveTimestamps && process.arch === 'ia32') {\n    process.emitWarning(\n      'Using the preserveTimestamps option in 32-bit node is not recommended;\\n\\n' +\n      '\\tsee https://github.com/jprichardson/node-fs-extra/issues/269',\n      'Warning', 'fs-extra-WARN0002'\n    )\n  }\n\n  const { srcStat, destStat } = stat.checkPathsSync(src, dest, 'copy', opts)\n  stat.checkParentPathsSync(src, srcStat, dest, 'copy')\n  if (opts.filter && !opts.filter(src, dest)) return\n  const destParent = path.dirname(dest)\n  if (!fs.existsSync(destParent)) mkdirsSync(destParent)\n  return getStats(destStat, src, dest, opts)\n}\n\nfunction getStats (destStat, src, dest, opts) {\n  const statSync = opts.dereference ? fs.statSync : fs.lstatSync\n  const srcStat = statSync(src)\n\n  if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)\n  else if (srcStat.isFile() ||\n           srcStat.isCharacterDevice() ||\n           srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts)\n  else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)\n  else if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)\n  else if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)\n  throw new Error(`Unknown file: ${src}`)\n}\n\nfunction onFile (srcStat, destStat, src, dest, opts) {\n  if (!destStat) return copyFile(srcStat, src, dest, opts)\n  return mayCopyFile(srcStat, src, dest, opts)\n}\n\nfunction mayCopyFile (srcStat, src, dest, opts) {\n  if (opts.overwrite) {\n    fs.unlinkSync(dest)\n    return copyFile(srcStat, src, dest, opts)\n  } else if (opts.errorOnExist) {\n    throw new Error(`'${dest}' already exists`)\n  }\n}\n\nfunction copyFile (srcStat, src, dest, opts) {\n  fs.copyFileSync(src, dest)\n  if (opts.preserveTimestamps) handleTimestamps(srcStat.mode, src, dest)\n  return setDestMode(dest, srcStat.mode)\n}\n\nfunction handleTimestamps (srcMode, src, dest) {\n  // Make sure the file is writable before setting the timestamp\n  // otherwise open fails with EPERM when invoked with 'r+'\n  // (through utimes call)\n  if (fileIsNotWritable(srcMode)) makeFileWritable(dest, srcMode)\n  return setDestTimestamps(src, dest)\n}\n\nfunction fileIsNotWritable (srcMode) {\n  return (srcMode & 0o200) === 0\n}\n\nfunction makeFileWritable (dest, srcMode) {\n  return setDestMode(dest, srcMode | 0o200)\n}\n\nfunction setDestMode (dest, srcMode) {\n  return fs.chmodSync(dest, srcMode)\n}\n\nfunction setDestTimestamps (src, dest) {\n  // The initial srcStat.atime cannot be trusted\n  // because it is modified by the read(2) system call\n  // (See https://nodejs.org/api/fs.html#fs_stat_time_values)\n  const updatedSrcStat = fs.statSync(src)\n  return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime)\n}\n\nfunction onDir (srcStat, destStat, src, dest, opts) {\n  if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)\n  return copyDir(src, dest, opts)\n}\n\nfunction mkDirAndCopy (srcMode, src, dest, opts) {\n  fs.mkdirSync(dest)\n  copyDir(src, dest, opts)\n  return setDestMode(dest, srcMode)\n}\n\nfunction copyDir (src, dest, opts) {\n  const dir = fs.opendirSync(src)\n\n  try {\n    let dirent\n\n    while ((dirent = dir.readSync()) !== null) {\n      copyDirItem(dirent.name, src, dest, opts)\n    }\n  } finally {\n    dir.closeSync()\n  }\n}\n\nfunction copyDirItem (item, src, dest, opts) {\n  const srcItem = path.join(src, item)\n  const destItem = path.join(dest, item)\n  if (opts.filter && !opts.filter(srcItem, destItem)) return\n  const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy', opts)\n  return getStats(destStat, srcItem, destItem, opts)\n}\n\nfunction onLink (destStat, src, dest, opts) {\n  let resolvedSrc = fs.readlinkSync(src)\n  if (opts.dereference) {\n    resolvedSrc = path.resolve(process.cwd(), resolvedSrc)\n  }\n\n  if (!destStat) {\n    return fs.symlinkSync(resolvedSrc, dest)\n  } else {\n    let resolvedDest\n    try {\n      resolvedDest = fs.readlinkSync(dest)\n    } catch (err) {\n      // dest exists and is a regular file or directory,\n      // Windows may throw UNKNOWN error. If dest already exists,\n      // fs throws error anyway, so no need to guard against it here.\n      if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlinkSync(resolvedSrc, dest)\n      throw err\n    }\n    if (opts.dereference) {\n      resolvedDest = path.resolve(process.cwd(), resolvedDest)\n    }\n    // If both symlinks resolve to the same target, they are still distinct symlinks\n    // that can be copied/overwritten. Only check subdirectory constraints when\n    // the resolved paths are different.\n    if (resolvedSrc !== resolvedDest) {\n      if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {\n        throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)\n      }\n\n      // prevent copy if src is a subdir of dest since unlinking\n      // dest in this case would result in removing src contents\n      // and therefore a broken symlink would be created.\n      if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {\n        throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)\n      }\n    }\n    return copyLink(resolvedSrc, dest)\n  }\n}\n\nfunction copyLink (resolvedSrc, dest) {\n  fs.unlinkSync(dest)\n  return fs.symlinkSync(resolvedSrc, dest)\n}\n\nmodule.exports = copySync\n"
  },
  {
    "path": "lib/copy/copy.js",
    "content": "'use strict'\n\nconst fs = require('../fs')\nconst path = require('path')\nconst { mkdirs } = require('../mkdirs')\nconst { pathExists } = require('../path-exists')\nconst { utimesMillis } = require('../util/utimes')\nconst stat = require('../util/stat')\nconst { asyncIteratorConcurrentProcess } = require('../util/async')\n\nasync function copy (src, dest, opts = {}) {\n  if (typeof opts === 'function') {\n    opts = { filter: opts }\n  }\n\n  opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now\n  opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber\n\n  // Warn about using preserveTimestamps on 32-bit node\n  if (opts.preserveTimestamps && process.arch === 'ia32') {\n    process.emitWarning(\n      'Using the preserveTimestamps option in 32-bit node is not recommended;\\n\\n' +\n      '\\tsee https://github.com/jprichardson/node-fs-extra/issues/269',\n      'Warning', 'fs-extra-WARN0001'\n    )\n  }\n\n  const { srcStat, destStat } = await stat.checkPaths(src, dest, 'copy', opts)\n\n  await stat.checkParentPaths(src, srcStat, dest, 'copy')\n\n  const include = await runFilter(src, dest, opts)\n\n  if (!include) return\n\n  // check if the parent of dest exists, and create it if it doesn't exist\n  const destParent = path.dirname(dest)\n  const dirExists = await pathExists(destParent)\n  if (!dirExists) {\n    await mkdirs(destParent)\n  }\n\n  await getStatsAndPerformCopy(destStat, src, dest, opts)\n}\n\nasync function runFilter (src, dest, opts) {\n  if (!opts.filter) return true\n  return opts.filter(src, dest)\n}\n\nasync function getStatsAndPerformCopy (destStat, src, dest, opts) {\n  const statFn = opts.dereference ? fs.stat : fs.lstat\n  const srcStat = await statFn(src)\n\n  if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)\n\n  if (\n    srcStat.isFile() ||\n    srcStat.isCharacterDevice() ||\n    srcStat.isBlockDevice()\n  ) return onFile(srcStat, destStat, src, dest, opts)\n\n  if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)\n  if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)\n  if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)\n  throw new Error(`Unknown file: ${src}`)\n}\n\nasync function onFile (srcStat, destStat, src, dest, opts) {\n  if (!destStat) return copyFile(srcStat, src, dest, opts)\n\n  if (opts.overwrite) {\n    await fs.unlink(dest)\n    return copyFile(srcStat, src, dest, opts)\n  }\n  if (opts.errorOnExist) {\n    throw new Error(`'${dest}' already exists`)\n  }\n}\n\nasync function copyFile (srcStat, src, dest, opts) {\n  await fs.copyFile(src, dest)\n  if (opts.preserveTimestamps) {\n    // Make sure the file is writable before setting the timestamp\n    // otherwise open fails with EPERM when invoked with 'r+'\n    // (through utimes call)\n    if (fileIsNotWritable(srcStat.mode)) {\n      await makeFileWritable(dest, srcStat.mode)\n    }\n\n    // Set timestamps and mode correspondingly\n\n    // Note that The initial srcStat.atime cannot be trusted\n    // because it is modified by the read(2) system call\n    // (See https://nodejs.org/api/fs.html#fs_stat_time_values)\n    const updatedSrcStat = await fs.stat(src)\n    await utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime)\n  }\n\n  return fs.chmod(dest, srcStat.mode)\n}\n\nfunction fileIsNotWritable (srcMode) {\n  return (srcMode & 0o200) === 0\n}\n\nfunction makeFileWritable (dest, srcMode) {\n  return fs.chmod(dest, srcMode | 0o200)\n}\n\nasync function onDir (srcStat, destStat, src, dest, opts) {\n  // the dest directory might not exist, create it\n  if (!destStat) {\n    await fs.mkdir(dest)\n  }\n\n  // iterate through the files in the current directory to copy everything\n  await asyncIteratorConcurrentProcess(await fs.opendir(src), async (item) => {\n    const srcItem = path.join(src, item.name)\n    const destItem = path.join(dest, item.name)\n\n    const include = await runFilter(srcItem, destItem, opts)\n    // only copy the item if it matches the filter function\n    if (include) {\n      const { destStat } = await stat.checkPaths(srcItem, destItem, 'copy', opts)\n      // If the item is a copyable file, `getStatsAndPerformCopy` will copy it\n      // If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively\n      await getStatsAndPerformCopy(destStat, srcItem, destItem, opts)\n    }\n  })\n\n  if (!destStat) {\n    await fs.chmod(dest, srcStat.mode)\n  }\n}\n\nasync function onLink (destStat, src, dest, opts) {\n  let resolvedSrc = await fs.readlink(src)\n  if (opts.dereference) {\n    resolvedSrc = path.resolve(process.cwd(), resolvedSrc)\n  }\n  if (!destStat) {\n    return fs.symlink(resolvedSrc, dest)\n  }\n\n  let resolvedDest = null\n  try {\n    resolvedDest = await fs.readlink(dest)\n  } catch (e) {\n    // dest exists and is a regular file or directory,\n    // Windows may throw UNKNOWN error. If dest already exists,\n    // fs throws error anyway, so no need to guard against it here.\n    if (e.code === 'EINVAL' || e.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest)\n    throw e\n  }\n  if (opts.dereference) {\n    resolvedDest = path.resolve(process.cwd(), resolvedDest)\n  }\n  // If both symlinks resolve to the same target, they are still distinct symlinks\n  // that can be copied/overwritten. Only check subdirectory constraints when\n  // the resolved paths are different.\n  if (resolvedSrc !== resolvedDest) {\n    if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {\n      throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)\n    }\n\n    // do not copy if src is a subdir of dest since unlinking\n    // dest in this case would result in removing src contents\n    // and therefore a broken symlink would be created.\n    if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {\n      throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)\n    }\n  }\n\n  // copy the link\n  await fs.unlink(dest)\n  return fs.symlink(resolvedSrc, dest)\n}\n\nmodule.exports = copy\n"
  },
  {
    "path": "lib/copy/index.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nmodule.exports = {\n  copy: u(require('./copy')),\n  copySync: require('./copy-sync')\n}\n"
  },
  {
    "path": "lib/empty/__tests__/empty-dir-sync.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('+ emptyDir()', () => {\n  let TEST_DIR\n\n  beforeEach(() => {\n    TEST_DIR = path.join(os.tmpdir(), 'test-fs-extra', 'empty-dir')\n    if (fs.existsSync(TEST_DIR)) {\n      fse.removeSync(TEST_DIR)\n    }\n    fse.ensureDirSync(TEST_DIR)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('> when directory exists and contains items', () => {\n    it('should delete all of the items', () => {\n      // verify nothing\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n      fse.ensureFileSync(path.join(TEST_DIR, 'some-file'))\n      fse.ensureFileSync(path.join(TEST_DIR, 'some-file-2'))\n      fse.ensureDirSync(path.join(TEST_DIR, 'some-dir'))\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 3)\n\n      fse.emptyDirSync(TEST_DIR)\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n    })\n  })\n\n  describe('> when directory exists and contains no items', () => {\n    it('should do nothing', () => {\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n      fse.emptyDirSync(TEST_DIR)\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n    })\n  })\n\n  describe('> when directory does not exist', () => {\n    it('should create it', () => {\n      fse.removeSync(TEST_DIR)\n      assert(!fs.existsSync(TEST_DIR))\n      fse.emptyDirSync(TEST_DIR)\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n    })\n  })\n})\n"
  },
  {
    "path": "lib/empty/__tests__/empty-dir.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('+ emptyDir()', () => {\n  let TEST_DIR\n\n  beforeEach(() => {\n    TEST_DIR = path.join(os.tmpdir(), 'test-fs-extra', 'empty-dir')\n    if (fs.existsSync(TEST_DIR)) {\n      fse.removeSync(TEST_DIR)\n    }\n    fse.ensureDirSync(TEST_DIR)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('> when directory exists and contains items', () => {\n    it('should delete all of the items', done => {\n      // verify nothing\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n      fse.ensureFileSync(path.join(TEST_DIR, 'some-file'))\n      fse.ensureFileSync(path.join(TEST_DIR, 'some-file-2'))\n      fse.ensureDirSync(path.join(TEST_DIR, 'some-dir'))\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 3)\n\n      fse.emptyDir(TEST_DIR, err => {\n        assert.ifError(err)\n        assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n        done()\n      })\n    })\n  })\n\n  describe('> when directory exists and contains no items', () => {\n    it('should do nothing', done => {\n      assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n      fse.emptyDir(TEST_DIR, err => {\n        assert.ifError(err)\n        assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n        done()\n      })\n    })\n  })\n\n  describe('> when directory does not exist', () => {\n    it('should create it', done => {\n      fse.removeSync(TEST_DIR)\n      assert(!fs.existsSync(TEST_DIR))\n      fse.emptyDir(TEST_DIR, err => {\n        assert.ifError(err)\n        assert.strictEqual(fs.readdirSync(TEST_DIR).length, 0)\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/empty/index.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nconst fs = require('../fs')\nconst path = require('path')\nconst mkdir = require('../mkdirs')\nconst remove = require('../remove')\n\nconst emptyDir = u(async function emptyDir (dir) {\n  let items\n  try {\n    items = await fs.readdir(dir)\n  } catch {\n    return mkdir.mkdirs(dir)\n  }\n\n  return Promise.all(items.map(item => remove.remove(path.join(dir, item))))\n})\n\nfunction emptyDirSync (dir) {\n  let items\n  try {\n    items = fs.readdirSync(dir)\n  } catch {\n    return mkdir.mkdirsSync(dir)\n  }\n\n  items.forEach(item => {\n    item = path.join(dir, item)\n    remove.removeSync(item)\n  })\n}\n\nmodule.exports = {\n  emptyDirSync,\n  emptydirSync: emptyDirSync,\n  emptyDir,\n  emptydir: emptyDir\n}\n"
  },
  {
    "path": "lib/ensure/__tests__/create.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('fs-extra', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'create')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ createFile', () => {\n    describe('> when the file and directory does not exist', () => {\n      it('should create the file', done => {\n        const file = path.join(TEST_DIR, Math.random() + 't-ne', Math.random() + '.txt')\n        assert(!fs.existsSync(file))\n        fse.createFile(file, err => {\n          assert.ifError(err)\n          assert(fs.existsSync(file))\n          done()\n        })\n      })\n    })\n\n    describe('> when the file does exist', () => {\n      it('should not modify the file', done => {\n        const file = path.join(TEST_DIR, Math.random() + 't-e', Math.random() + '.txt')\n        fse.mkdirsSync(path.dirname(file))\n        fs.writeFileSync(file, 'hello world')\n        fse.createFile(file, err => {\n          assert.ifError(err)\n          assert.strictEqual(fs.readFileSync(file, 'utf8'), 'hello world')\n          done()\n        })\n      })\n\n      it('should give clear error if node in directory tree is a file', done => {\n        const existingFile = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt')\n        fse.mkdirsSync(path.dirname(existingFile))\n        fs.writeFileSync(existingFile, '')\n\n        const file = path.join(existingFile, Math.random() + '.txt')\n        fse.createFile(file, err => {\n          assert.strictEqual(err.code, 'ENOTDIR')\n          done()\n        })\n      })\n    })\n  })\n\n  describe('+ createFileSync', () => {\n    describe('> when the file and directory does not exist', () => {\n      it('should create the file', () => {\n        const file = path.join(TEST_DIR, Math.random() + 'ts-ne', Math.random() + '.txt')\n        assert(!fs.existsSync(file))\n        fse.createFileSync(file)\n        assert(fs.existsSync(file))\n      })\n    })\n\n    describe('> when the file does exist', () => {\n      it('should not modify the file', () => {\n        const file = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt')\n        fse.mkdirsSync(path.dirname(file))\n        fs.writeFileSync(file, 'hello world')\n        fse.createFileSync(file)\n        assert.strictEqual(fs.readFileSync(file, 'utf8'), 'hello world')\n      })\n\n      it('should give clear error if node in directory tree is a file', () => {\n        const existingFile = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt')\n        fse.mkdirsSync(path.dirname(existingFile))\n        fs.writeFileSync(existingFile, '')\n\n        const file = path.join(existingFile, Math.random() + '.txt')\n        try {\n          fse.createFileSync(file)\n          assert.fail()\n        } catch (err) {\n          assert.strictEqual(err.code, 'ENOTDIR')\n        }\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/ensure/__tests__/ensure.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('fs-extra', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ensure')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ ensureFile()', () => {\n    describe('> when file exists', () => {\n      it('should not do anything', done => {\n        const file = path.join(TEST_DIR, 'file.txt')\n        fs.writeFileSync(file, 'blah')\n\n        assert(fs.existsSync(file))\n        fse.ensureFile(file, err => {\n          assert.ifError(err)\n          assert(fs.existsSync(file))\n          done()\n        })\n      })\n    })\n\n    describe('> when file does not exist', () => {\n      it('should create the file', done => {\n        const file = path.join(TEST_DIR, 'dir/that/does/not/exist', 'file.txt')\n\n        assert(!fs.existsSync(file))\n        fse.ensureFile(file, err => {\n          assert.ifError(err)\n          assert(fs.existsSync(file))\n          done()\n        })\n      })\n    })\n\n    describe('> when there is a directory at that path', () => {\n      it('should error', done => {\n        const p = path.join(TEST_DIR, 'somedir')\n        fs.mkdirSync(p)\n\n        fse.ensureFile(p, err => {\n          assert(err)\n          assert.strictEqual(err.code, 'EISDIR')\n          done()\n        })\n      })\n    })\n  })\n\n  describe('+ ensureFileSync()', () => {\n    describe('> when file exists', () => {\n      it('should not do anything', () => {\n        const file = path.join(TEST_DIR, 'file.txt')\n        fs.writeFileSync(file, 'blah')\n\n        assert(fs.existsSync(file))\n        fse.ensureFileSync(file)\n        assert(fs.existsSync(file))\n      })\n    })\n\n    describe('> when file does not exist', () => {\n      it('should create the file', () => {\n        const file = path.join(TEST_DIR, 'dir/that/does/not/exist', 'file.txt')\n\n        assert(!fs.existsSync(file))\n        fse.ensureFileSync(file)\n        assert(fs.existsSync(file))\n      })\n    })\n\n    describe('> when there is a directory at that path', () => {\n      it('should error', () => {\n        const p = path.join(TEST_DIR, 'somedir2')\n        fs.mkdirSync(p)\n\n        assert.throws(() => {\n          try {\n            fse.ensureFileSync(p)\n          } catch (e) {\n            assert.strictEqual(e.code, 'EISDIR')\n            throw e\n          }\n        })\n      })\n    })\n  })\n\n  describe('+ ensureDir()', () => {\n    describe('> when dir exists', () => {\n      it('should not do anything', done => {\n        const dir = path.join(TEST_DIR, 'dir/does/not/exist')\n        fse.mkdirpSync(dir)\n\n        assert(fs.existsSync(dir))\n        fse.ensureDir(dir, err => {\n          assert.ifError(err)\n          assert(fs.existsSync(dir))\n          done()\n        })\n      })\n    })\n\n    describe('> when dir does not exist', () => {\n      it('should create the dir', done => {\n        const dir = path.join(TEST_DIR, 'dir/that/does/not/exist')\n\n        assert(!fs.existsSync(dir))\n        fse.ensureDir(dir, err => {\n          assert.ifError(err)\n          assert(fs.existsSync(dir))\n          done()\n        })\n      })\n    })\n  })\n\n  describe('+ ensureDirSync()', () => {\n    describe('> when dir exists', () => {\n      it('should not do anything', () => {\n        const dir = path.join(TEST_DIR, 'dir/does/not/exist')\n        fse.mkdirpSync(dir)\n\n        assert(fs.existsSync(dir))\n        fse.ensureDirSync(dir)\n        assert(fs.existsSync(dir))\n      })\n    })\n\n    describe('> when dir does not exist', () => {\n      it('should create the dir', () => {\n        const dir = path.join(TEST_DIR, 'dir/that/does/not/exist')\n\n        assert(!fs.existsSync(dir))\n        fse.ensureDirSync(dir)\n        assert(fs.existsSync(dir))\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/ensure/__tests__/link.test.js",
    "content": "'use strict'\n\nconst CWD = process.cwd()\n\nconst fs = require('graceful-fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst ensureLink = fse.ensureLink\nconst ensureLinkSync = fse.ensureLinkSync\n\n/* global afterEach, beforeEach, describe, it, after, before */\n\ndescribe('fse-ensure-link', () => {\n  const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ensure-symlink')\n\n  const tests = [\n    // [[srcpath, dstpath], fs.link expect, ensureLink expect]\n    [['./foo.txt', './link.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './dir-foo/link.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './empty-dir/link.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './real-alpha/link.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './real-alpha/real-beta/link.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './real-alpha/real-beta/real-gamma/link.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './alpha/link.txt'], 'file-error', 'file-success'],\n    [['./foo.txt', './alpha/beta/link.txt'], 'file-error', 'file-success'],\n    [['./foo.txt', './alpha/beta/gamma/link.txt'], 'file-error', 'file-success'],\n    [['./foo.txt', './link-foo.txt'], 'file-error', 'file-success'],\n    [['./dir-foo/foo.txt', './link-foo.txt'], 'file-error', 'file-error'],\n    [['./missing.txt', './link.txt'], 'file-error', 'file-error'],\n    [['./missing.txt', './missing-dir/link.txt'], 'file-error', 'file-error'],\n    [['./foo.txt', './link.txt'], 'file-success', 'file-success'],\n    [['./dir-foo/foo.txt', './link.txt'], 'file-success', 'file-success'],\n    [['./missing.txt', './link.txt'], 'file-error', 'file-error'],\n    [['../foo.txt', './link.txt'], 'file-error', 'file-error'],\n    [['../dir-foo/foo.txt', './link.txt'], 'file-error', 'file-error'],\n    // error is thrown if destination path exists\n    [['./foo.txt', './dir-foo/foo.txt'], 'file-error', 'file-error'],\n    [[path.resolve(path.join(TEST_DIR, './foo.txt')), './link.txt'], 'file-success', 'file-success'],\n    [[path.resolve(path.join(TEST_DIR, './dir-foo/foo.txt')), './link.txt'], 'file-success', 'file-success'],\n    [[path.resolve(path.join(TEST_DIR, './missing.txt')), './link.txt'], 'file-error', 'file-error'],\n    [[path.resolve(path.join(TEST_DIR, '../foo.txt')), './link.txt'], 'file-error', 'file-error'],\n    [[path.resolve(path.join(TEST_DIR, '../dir-foo/foo.txt')), './link.txt'], 'file-error', 'file-error']\n  ]\n\n  before(() => {\n    fse.emptyDirSync(TEST_DIR)\n    process.chdir(TEST_DIR)\n  })\n\n  beforeEach(() => {\n    fs.writeFileSync('./foo.txt', 'foo\\n')\n    fse.mkdirsSync('empty-dir')\n    fse.mkdirsSync('dir-foo')\n    fs.writeFileSync('dir-foo/foo.txt', 'dir-foo\\n')\n    fse.mkdirsSync('dir-bar')\n    fs.writeFileSync('dir-bar/bar.txt', 'dir-bar\\n')\n    fse.mkdirsSync('real-alpha/real-beta/real-gamma')\n    fs.linkSync('foo.txt', 'link-foo.txt')\n  })\n\n  afterEach(done => fse.emptyDir(TEST_DIR, done))\n\n  after(() => {\n    process.chdir(CWD)\n    fse.removeSync(TEST_DIR)\n  })\n\n  function fileSuccess (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n\n    it(`should create link file using src ${srcpath} and dst ${dstpath}`, done => {\n      const callback = err => {\n        if (err) return done(err)\n\n        const srcContent = fs.readFileSync(srcpath, 'utf8')\n        const dstDir = path.dirname(dstpath)\n        const dstBasename = path.basename(dstpath)\n        const isSymlink = fs.lstatSync(dstpath).isFile()\n        const dstContent = fs.readFileSync(dstpath, 'utf8')\n        const dstDirContents = fs.readdirSync(dstDir)\n\n        assert.strictEqual(isSymlink, true)\n        assert.strictEqual(srcContent, dstContent)\n        assert(dstDirContents.indexOf(dstBasename) >= 0)\n        return done()\n      }\n      args.push(callback)\n      return fn(...args)\n    })\n  }\n\n  function fileError (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n\n    it(`should return error when creating link file using src ${srcpath} and dst ${dstpath}`, done => {\n      const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))\n      const callback = err => {\n        assert.strictEqual(err instanceof Error, true)\n        // ensure that directories aren't created if there's an error\n        const dstdirExistsAfter = fs.existsSync(path.dirname(dstpath))\n        assert.strictEqual(dstdirExistsBefore, dstdirExistsAfter)\n        return done()\n      }\n      args.push(callback)\n      return fn(...args)\n    })\n  }\n\n  function fileSuccessSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n\n    it(`should create link file using src ${srcpath} and dst ${dstpath}`, () => {\n      fn(...args)\n      const srcContent = fs.readFileSync(srcpath, 'utf8')\n      const dstDir = path.dirname(dstpath)\n      const dstBasename = path.basename(dstpath)\n      const isSymlink = fs.lstatSync(dstpath).isFile()\n      const dstContent = fs.readFileSync(dstpath, 'utf8')\n      const dstDirContents = fs.readdirSync(dstDir)\n      assert.strictEqual(isSymlink, true)\n      assert.strictEqual(srcContent, dstContent)\n      assert(dstDirContents.indexOf(dstBasename) >= 0)\n    })\n  }\n\n  function fileErrorSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n\n    it(`should throw error using src ${srcpath} and dst ${dstpath}`, () => {\n      // will fail if dstdir is created and there's an error\n      const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))\n      let err = null\n      try {\n        fn(...args)\n      } catch (e) {\n        err = e\n      }\n      assert.strictEqual(err instanceof Error, true)\n      const dstdirExistsAfter = fs.existsSync(path.dirname(dstpath))\n      assert.strictEqual(dstdirExistsBefore, dstdirExistsAfter)\n    })\n  }\n\n  describe('fs.link()', () => {\n    const fn = fs.link\n    tests.forEach(test => {\n      const args = test[0].slice(0)\n      const nativeBehavior = test[1]\n      // const newBehavior = test[2]\n      if (nativeBehavior === 'file-success') fileSuccess(args, fn)\n      if (nativeBehavior === 'file-error') fileError(args, fn)\n    })\n  })\n\n  describe('ensureLink()', () => {\n    const fn = ensureLink\n    tests.forEach(test => {\n      const args = test[0].slice(0)\n      // const nativeBehavior = test[1]\n      const newBehavior = test[2]\n      if (newBehavior === 'file-success') fileSuccess(args, fn)\n      if (newBehavior === 'file-error') fileError(args, fn)\n    })\n  })\n\n  describe('ensureLink() promise support', () => {\n    tests.filter(test => test[2] === 'file-success').forEach(test => {\n      const args = test[0].slice(0)\n      const srcpath = args[0]\n      const dstpath = args[1]\n\n      it(`should create link file using src ${srcpath} and dst ${dstpath}`, () => {\n        return ensureLink(srcpath, dstpath)\n          .then(() => {\n            const srcContent = fs.readFileSync(srcpath, 'utf8')\n            const dstDir = path.dirname(dstpath)\n            const dstBasename = path.basename(dstpath)\n            const isSymlink = fs.lstatSync(dstpath).isFile()\n            const dstContent = fs.readFileSync(dstpath, 'utf8')\n            const dstDirContents = fs.readdirSync(dstDir)\n\n            assert.strictEqual(isSymlink, true)\n            assert.strictEqual(srcContent, dstContent)\n            assert(dstDirContents.indexOf(dstBasename) >= 0)\n          })\n      })\n    })\n  })\n\n  describe('fs.linkSync()', () => {\n    const fn = fs.linkSync\n    tests.forEach(test => {\n      const args = test[0].slice(0)\n      const nativeBehavior = test[1]\n      // const newBehavior = test[2]\n      if (nativeBehavior === 'file-success') fileSuccessSync(args, fn)\n      if (nativeBehavior === 'file-error') fileErrorSync(args, fn)\n    })\n  })\n\n  describe('ensureLinkSync()', () => {\n    const fn = ensureLinkSync\n    tests.forEach(test => {\n      const args = test[0].slice(0)\n      // const nativeBehavior = test[1]\n      const newBehavior = test[2]\n      if (newBehavior === 'file-success') fileSuccessSync(args, fn)\n      if (newBehavior === 'file-error') fileErrorSync(args, fn)\n    })\n  })\n})\n"
  },
  {
    "path": "lib/ensure/__tests__/symlink-paths.test.js",
    "content": "'use strict'\n\nconst CWD = process.cwd()\n\nconst fs = require('graceful-fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst _symlinkPaths = require('../symlink-paths')\nconst symlinkPaths = _symlinkPaths.symlinkPaths\nconst symlinkPathsSync = _symlinkPaths.symlinkPathsSync\nconst TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ensure-symlink')\n\n/* global afterEach, beforeEach, describe, it, after, before */\n\ndescribe('symlink-type', () => {\n  before(() => {\n    fse.emptyDirSync(TEST_DIR)\n    process.chdir(TEST_DIR)\n  })\n\n  beforeEach(() => {\n    fs.writeFileSync('./foo.txt', 'foo\\n')\n    fse.mkdirsSync('./empty-dir')\n    fse.mkdirsSync('./dir-foo')\n    fs.writeFileSync('./dir-foo/foo.txt', 'dir-foo\\n')\n    fse.mkdirsSync('./dir-bar')\n    fs.writeFileSync('./dir-bar/bar.txt', 'dir-bar\\n')\n    fse.mkdirsSync('./real-alpha/real-beta/real-gamma')\n  })\n\n  afterEach(done => fse.emptyDir(TEST_DIR, done))\n\n  after(() => {\n    process.chdir(CWD)\n    fse.removeSync(TEST_DIR)\n  })\n\n  const tests = [\n    [['foo.txt', 'symlink.txt'], { toCwd: 'foo.txt', toDst: 'foo.txt' }], // smart && nodestyle\n    [['foo.txt', 'empty-dir/symlink.txt'], { toCwd: 'foo.txt', toDst: '../foo.txt' }], // smart\n    [['../foo.txt', 'empty-dir/symlink.txt'], { toCwd: 'foo.txt', toDst: '../foo.txt' }], // nodestyle\n    [['foo.txt', 'dir-bar/symlink.txt'], { toCwd: 'foo.txt', toDst: '../foo.txt' }], // smart\n    [['../foo.txt', 'dir-bar/symlink.txt'], { toCwd: 'foo.txt', toDst: '../foo.txt' }], // nodestyle\n    // this is to preserve node's symlink capability these arguments say create\n    // a link to 'dir-foo/foo.txt' this works because it exists this is unlike\n    // the previous example with 'empty-dir' because 'empty-dir/foo.txt' does not exist.\n    [['foo.txt', 'dir-foo/symlink.txt'], { toCwd: 'dir-foo/foo.txt', toDst: 'foo.txt' }], // nodestyle\n    [['foo.txt', 'real-alpha/real-beta/real-gamma/symlink.txt'], { toCwd: 'foo.txt', toDst: '../../../foo.txt' }]\n  ]\n\n  // formats paths to pass on multiple operating systems\n  tests.forEach(test => {\n    test[0][0] = path.join(test[0][0])\n    test[0][1] = path.join(test[0][1])\n    test[1] = {\n      toCwd: path.join(test[1].toCwd),\n      toDst: path.join(test[1].toDst)\n    }\n  })\n\n  describe('symlinkPaths()', () => {\n    tests.forEach(test => {\n      const args = test[0].slice(0)\n      const expectedRelativePaths = test[1]\n      it(`should return '${JSON.stringify(expectedRelativePaths)}' when src '${args[0]}' and dst is '${args[1]}'`, done => {\n        const callback = (err, relativePaths) => {\n          if (err) done(err)\n          assert.deepStrictEqual(relativePaths, expectedRelativePaths)\n          done()\n        }\n        args.push(callback)\n        return symlinkPaths(...args)\n      })\n    })\n  })\n\n  describe('symlinkPathsSync()', () => {\n    tests.forEach(test => {\n      const args = test[0].slice(0)\n      const expectedRelativePaths = test[1]\n      it(`should return '${JSON.stringify(expectedRelativePaths)}' when src '${args[0]}' and dst is '${args[1]}'`, () => {\n        const relativePaths = symlinkPathsSync(...args)\n        assert.deepStrictEqual(relativePaths, expectedRelativePaths)\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/ensure/__tests__/symlink-type.test.js",
    "content": "'use strict'\n\nconst CWD = process.cwd()\n\nconst fs = require('graceful-fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst _symlinkType = require('../symlink-type')\nconst symlinkType = _symlinkType.symlinkType\nconst symlinkTypeSync = _symlinkType.symlinkTypeSync\nconst TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ensure-symlink')\n\n/* global afterEach, beforeEach, describe, it, after, before */\n\ndescribe('symlink-type', () => {\n  before(() => {\n    fse.emptyDirSync(TEST_DIR)\n    process.chdir(TEST_DIR)\n  })\n\n  beforeEach(() => {\n    fs.writeFileSync('./foo.txt', 'foo\\n')\n    fse.mkdirsSync('./empty-dir')\n    fse.mkdirsSync('./dir-foo')\n    fs.writeFileSync('./dir-foo/foo.txt', 'dir-foo\\n')\n    fse.mkdirsSync('./dir-bar')\n    fs.writeFileSync('./dir-bar/bar.txt', 'dir-bar\\n')\n    fse.mkdirsSync('./real-alpha/real-beta/real-gamma')\n  })\n\n  afterEach(done => fse.emptyDir(TEST_DIR, done))\n\n  after(() => {\n    process.chdir(CWD)\n    fse.removeSync(TEST_DIR)\n  })\n\n  const tests = {\n    success: [\n      // [{arguments} [srcpath, dirpath, [type] , result]\n      // smart file type checking\n      [['./foo.txt'], 'file'],\n      [['./empty-dir'], 'dir'],\n      [['./dir-foo/foo.txt'], 'file'],\n      [['./dir-bar'], 'dir'],\n      [['./dir-bar/bar.txt'], 'file'],\n      [['./real-alpha/real-beta/real-gamma'], 'dir'],\n      // force dir\n      [['./foo.txt', 'dir'], 'dir'],\n      [['./empty-dir', 'dir'], 'dir'],\n      [['./dir-foo/foo.txt', 'dir'], 'dir'],\n      [['./dir-bar', 'dir'], 'dir'],\n      [['./dir-bar/bar.txt', 'dir'], 'dir'],\n      [['./real-alpha/real-beta/real-gamma', 'dir'], 'dir'],\n      // force file\n      [['./foo.txt', 'file'], 'file'],\n      [['./empty-dir', 'file'], 'file'],\n      [['./dir-foo/foo.txt', 'file'], 'file'],\n      [['./dir-bar', 'file'], 'file'],\n      [['./dir-bar/bar.txt', 'file'], 'file'],\n      [['./real-alpha/real-beta/real-gamma', 'file'], 'file'],\n      // default for files or dirs that don't exist is file\n      [['./missing.txt'], 'file'],\n      [['./missing'], 'file'],\n      [['./missing.txt'], 'file'],\n      [['./missing'], 'file'],\n      [['./empty-dir/missing.txt'], 'file'],\n      [['./empty-dir/missing'], 'file'],\n      [['./empty-dir/missing.txt'], 'file'],\n      [['./empty-dir/missing'], 'file'],\n      // when src doesnt exist and provided type 'file'\n      [['./missing.txt', 'file'], 'file'],\n      [['./missing', 'file'], 'file'],\n      [['./missing.txt', 'file'], 'file'],\n      [['./missing', 'file'], 'file'],\n      [['./empty-dir/missing.txt', 'file'], 'file'],\n      [['./empty-dir/missing', 'file'], 'file'],\n      [['./empty-dir/missing.txt', 'file'], 'file'],\n      [['./empty-dir/missing', 'file'], 'file'],\n      // when src doesnt exist and provided type 'dir'\n      [['./missing.txt', 'dir'], 'dir'],\n      [['./missing', 'dir'], 'dir'],\n      [['./missing.txt', 'dir'], 'dir'],\n      [['./missing', 'dir'], 'dir'],\n      [['./empty-dir/missing.txt', 'dir'], 'dir'],\n      [['./empty-dir/missing', 'dir'], 'dir'],\n      [['./empty-dir/missing.txt', 'dir'], 'dir'],\n      [['./empty-dir/missing', 'dir'], 'dir']\n    ]\n  }\n\n  describe('symlinkType()', () => {\n    tests.success.forEach(test => {\n      const args = test[0].slice(0)\n      const expectedType = test[1]\n      it(`should return '${expectedType}' when src '${args[0]}'`, done => {\n        const callback = (err, type) => {\n          if (err) done(err)\n          assert.strictEqual(type, expectedType)\n          done()\n        }\n        args.push(callback)\n        return symlinkType(...args)\n      })\n    })\n  })\n\n  describe('symlinkTypeSync()', () => {\n    tests.success.forEach(test => {\n      const args = test[0]\n      const expectedType = test[1]\n      it(`should return '${expectedType}' when src '${args[0]}'`, () => {\n        const type = symlinkTypeSync(...args)\n        assert.strictEqual(type, expectedType)\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/ensure/__tests__/symlink.test.js",
    "content": "'use strict'\n\nconst CWD = process.cwd()\n\nconst fs = require('graceful-fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst _symlinkPaths = require('../symlink-paths')\nconst symlinkPathsSync = _symlinkPaths.symlinkPathsSync\nconst ensureSymlink = fse.ensureSymlink\nconst ensureSymlinkSync = fse.ensureSymlinkSync\n\n/* global afterEach, beforeEach, describe, it, after, before */\n\nlet TEST_DIR\n\ndescribe('fse-ensure-symlink', () => {\n  TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ensure-symlink')\n\n  const tests = [\n    // [[srcpath, dstpath], fs.symlink expect, fse.ensureSymlink expect]\n    [['./foo.txt', './symlink.txt'], 'file-success', 'file-success'],\n    [['../foo.txt', './empty-dir/symlink.txt'], 'file-success', 'file-success'],\n    [['../foo.txt', './empty-dir/symlink.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './dir-foo/symlink.txt'], 'file-success', 'file-success'],\n    [['./foo.txt', './empty-dir/symlink.txt'], 'file-broken', 'file-success'],\n    [['./foo.txt', './real-alpha/symlink.txt'], 'file-broken', 'file-success'],\n    [['./foo.txt', './real-alpha/real-beta/symlink.txt'], 'file-broken', 'file-success'],\n    [['./foo.txt', './real-alpha/real-beta/real-gamma/symlink.txt'], 'file-broken', 'file-success'],\n    [['./foo.txt', './alpha/symlink.txt'], 'file-error', 'file-success'],\n    [['./foo.txt', './alpha/beta/symlink.txt'], 'file-error', 'file-success'],\n    [['./foo.txt', './alpha/beta/gamma/symlink.txt'], 'file-error', 'file-success'],\n    [['./foo.txt', './real-symlink.txt'], 'file-error', 'file-success'],\n    [['./dir-foo/foo.txt', './real-symlink.txt'], 'file-error', 'file-error'],\n    [['./missing.txt', './symlink.txt'], 'file-broken', 'file-error'],\n    [['./missing.txt', './missing-dir/symlink.txt'], 'file-error', 'file-error'],\n    // error is thrown if destination path exists\n    [['./foo.txt', './dir-foo/foo.txt'], 'file-error', 'file-error'],\n    [['./dir-foo', './symlink-dir-foo'], 'dir-success', 'dir-success'],\n    [['../dir-bar', './dir-foo/symlink-dir-bar'], 'dir-success', 'dir-success'],\n    [['./dir-bar', './dir-foo/symlink-dir-bar'], 'dir-broken', 'dir-success'],\n    [['./dir-bar', './empty-dir/symlink-dir-bar'], 'dir-broken', 'dir-success'],\n    [['./dir-bar', './real-alpha/symlink-dir-bar'], 'dir-broken', 'dir-success'],\n    [['./dir-bar', './real-alpha/real-beta/symlink-dir-bar'], 'dir-broken', 'dir-success'],\n    [['./dir-bar', './real-alpha/real-beta/real-gamma/symlink-dir-bar'], 'dir-broken', 'dir-success'],\n    [['./dir-foo', './alpha/dir-foo'], 'dir-error', 'dir-success'],\n    [['./dir-foo', './alpha/beta/dir-foo'], 'dir-error', 'dir-success'],\n    [['./dir-foo', './alpha/beta/gamma/dir-foo'], 'dir-error', 'dir-success'],\n    [['./dir-foo', './real-symlink-dir-foo'], 'dir-error', 'dir-success'],\n    [['./dir-bar', './real-symlink-dir-foo'], 'dir-error', 'dir-error'],\n    [['./missing', './dir-foo/symlink-dir-missing'], 'dir-broken', 'dir-error'],\n    // error is thrown if destination path exists\n    [['./dir-foo', './real-alpha/real-beta'], 'dir-error', 'dir-error'],\n    [[path.resolve(path.join(TEST_DIR, './foo.txt')), './symlink.txt'], 'file-success', 'file-success'],\n    [[path.resolve(path.join(TEST_DIR, './dir-foo/foo.txt')), './symlink.txt'], 'file-success', 'file-success'],\n    [[path.resolve(path.join(TEST_DIR, './missing.txt')), './symlink.txt'], 'file-broken', 'file-error'],\n    [[path.resolve(path.join(TEST_DIR, '../foo.txt')), './symlink.txt'], 'file-broken', 'file-error'],\n    [[path.resolve(path.join(TEST_DIR, '../dir-foo/foo.txt')), './symlink.txt'], 'file-broken', 'file-error']\n  ]\n\n  before(() => {\n    fse.emptyDirSync(TEST_DIR)\n    process.chdir(TEST_DIR)\n  })\n\n  beforeEach(() => {\n    fs.writeFileSync('./foo.txt', 'foo\\n')\n    fse.mkdirsSync('empty-dir')\n    fse.mkdirsSync('dir-foo')\n    fs.writeFileSync('dir-foo/foo.txt', 'dir-foo\\n')\n    fse.mkdirsSync('dir-bar')\n    fs.writeFileSync('dir-bar/bar.txt', 'dir-bar\\n')\n    fse.mkdirsSync('real-alpha/real-beta/real-gamma')\n    fs.symlinkSync('foo.txt', 'real-symlink.txt')\n    fs.symlinkSync('dir-foo', 'real-symlink-dir-foo')\n  })\n\n  afterEach(done => fse.emptyDir(TEST_DIR, done))\n\n  after(() => {\n    process.chdir(CWD)\n    fse.removeSync(TEST_DIR)\n  })\n\n  function fileSuccess (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create symlink file using src ${srcpath} and dst ${dstpath}`, done => {\n      const callback = err => {\n        if (err) return done(err)\n        const relative = symlinkPathsSync(srcpath, dstpath)\n        const srcContent = fs.readFileSync(relative.toCwd, 'utf8')\n        const dstDir = path.dirname(dstpath)\n        const dstBasename = path.basename(dstpath)\n        const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n        const dstContent = fs.readFileSync(dstpath, 'utf8')\n        const dstDirContents = fs.readdirSync(dstDir)\n        assert.strictEqual(isSymlink, true)\n        assert.strictEqual(srcContent, dstContent)\n        assert(dstDirContents.indexOf(dstBasename) >= 0)\n        return done()\n      }\n      return fn(...args, callback)\n    })\n  }\n\n  function fileBroken (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create broken symlink file using src ${srcpath} and dst ${dstpath}`, done => {\n      const callback = err => {\n        if (err) return done(err)\n        const dstDir = path.dirname(dstpath)\n        const dstBasename = path.basename(dstpath)\n        const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n        const dstDirContents = fs.readdirSync(dstDir)\n        assert.strictEqual(isSymlink, true)\n        assert(dstDirContents.indexOf(dstBasename) >= 0)\n        assert.throws(() => fs.readFileSync(dstpath, 'utf8'), Error)\n        return done()\n      }\n      return fn(...args, callback)\n    })\n  }\n\n  function fileError (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should return error when creating symlink file using src ${srcpath} and dst ${dstpath}`, done => {\n      const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))\n      const callback = err => {\n        assert.strictEqual(err instanceof Error, true)\n        // ensure that directories aren't created if there's an error\n        const dstdirExistsAfter = fs.existsSync(path.dirname(dstpath))\n        assert.strictEqual(dstdirExistsBefore, dstdirExistsAfter)\n        return done()\n      }\n      return fn(...args, callback)\n    })\n  }\n\n  function dirSuccess (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create symlink dir using src ${srcpath} and dst ${dstpath}`, done => {\n      const callback = err => {\n        if (err) return done(err)\n        const relative = symlinkPathsSync(srcpath, dstpath)\n        const srcContents = fs.readdirSync(relative.toCwd)\n        const dstDir = path.dirname(dstpath)\n        const dstBasename = path.basename(dstpath)\n        const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n        const dstContents = fs.readdirSync(dstpath)\n        const dstDirContents = fs.readdirSync(dstDir)\n        assert.strictEqual(isSymlink, true)\n        assert.deepStrictEqual(srcContents, dstContents)\n        assert(dstDirContents.indexOf(dstBasename) >= 0)\n        return done()\n      }\n      return fn(...args, callback)\n    })\n  }\n\n  function dirBroken (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create broken symlink dir using src ${srcpath} and dst ${dstpath}`, done => {\n      const callback = err => {\n        if (err) return done(err)\n        const dstDir = path.dirname(dstpath)\n        const dstBasename = path.basename(dstpath)\n        const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n        const dstDirContents = fs.readdirSync(dstDir)\n        assert.strictEqual(isSymlink, true)\n        assert(dstDirContents.indexOf(dstBasename) >= 0)\n        assert.throws(() => fs.readdirSync(dstpath), Error)\n        return done()\n      }\n      return fn(...args, callback)\n    })\n  }\n\n  function dirError (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should return error when creating symlink dir using src ${srcpath} and dst ${dstpath}`, done => {\n      const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))\n      const callback = err => {\n        assert.strictEqual(err instanceof Error, true)\n        // ensure that directories aren't created if there's an error\n        const dstdirExistsAfter = fs.existsSync(path.dirname(dstpath))\n        assert.strictEqual(dstdirExistsBefore, dstdirExistsAfter)\n        return done()\n      }\n      return fn(...args, callback)\n    })\n  }\n\n  function fileSuccessSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create symlink file using src ${srcpath} and dst ${dstpath}`, () => {\n      fn(...args)\n      const relative = symlinkPathsSync(srcpath, dstpath)\n      const srcContent = fs.readFileSync(relative.toCwd, 'utf8')\n      const dstDir = path.dirname(dstpath)\n      const dstBasename = path.basename(dstpath)\n      const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n      const dstContent = fs.readFileSync(dstpath, 'utf8')\n      const dstDirContents = fs.readdirSync(dstDir)\n      assert.strictEqual(isSymlink, true)\n      assert.strictEqual(srcContent, dstContent)\n      assert(dstDirContents.indexOf(dstBasename) >= 0)\n    })\n  }\n\n  function fileBrokenSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create broken symlink file using src ${srcpath} and dst ${dstpath}`, () => {\n      fn(...args)\n      const dstDir = path.dirname(dstpath)\n      const dstBasename = path.basename(dstpath)\n      const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n      const dstDirContents = fs.readdirSync(dstDir)\n      assert.strictEqual(isSymlink, true)\n      assert(dstDirContents.indexOf(dstBasename) >= 0)\n      assert.throws(() => fs.readFileSync(dstpath, 'utf8'), Error)\n    })\n  }\n\n  function fileErrorSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should throw error using src ${srcpath} and dst ${dstpath}`, () => {\n      const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))\n      let err = null\n      try {\n        fn(...args)\n      } catch (e) {\n        err = e\n      }\n      assert.strictEqual(err instanceof Error, true)\n      const dstdirExistsAfter = fs.existsSync(path.dirname(dstpath))\n      assert.strictEqual(dstdirExistsBefore, dstdirExistsAfter)\n    })\n  }\n\n  function dirSuccessSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create symlink dir using src ${srcpath} and dst ${dstpath}`, () => {\n      fn(...args)\n      const relative = symlinkPathsSync(srcpath, dstpath)\n      const srcContents = fs.readdirSync(relative.toCwd)\n      const dstDir = path.dirname(dstpath)\n      const dstBasename = path.basename(dstpath)\n      const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n      const dstContents = fs.readdirSync(dstpath)\n      const dstDirContents = fs.readdirSync(dstDir)\n      assert.strictEqual(isSymlink, true)\n      assert.deepStrictEqual(srcContents, dstContents)\n      assert(dstDirContents.indexOf(dstBasename) >= 0)\n    })\n  }\n\n  function dirBrokenSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should create broken symlink dir using src ${srcpath} and dst ${dstpath}`, () => {\n      fn(...args)\n      const dstDir = path.dirname(dstpath)\n      const dstBasename = path.basename(dstpath)\n      const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n      const dstDirContents = fs.readdirSync(dstDir)\n      assert.strictEqual(isSymlink, true)\n      assert(dstDirContents.indexOf(dstBasename) >= 0)\n      assert.throws(() => fs.readdirSync(dstpath), Error)\n    })\n  }\n\n  function dirErrorSync (args, fn) {\n    const srcpath = args[0]\n    const dstpath = args[1]\n    it(`should throw error when creating symlink dir using src ${srcpath} and dst ${dstpath}`, () => {\n      const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))\n      let err = null\n      try {\n        fn(...args)\n      } catch (e) {\n        err = e\n      }\n      assert.strictEqual(err instanceof Error, true)\n      const dstdirExistsAfter = fs.existsSync(path.dirname(dstpath))\n      assert.strictEqual(dstdirExistsBefore, dstdirExistsAfter)\n    })\n  }\n\n  describe('ensureSymlink()', () => {\n    const fn = ensureSymlink\n    tests.forEach(test => {\n      const args = test[0]\n      // const nativeBehavior = test[1]\n      const newBehavior = test[2]\n      if (newBehavior === 'file-success') fileSuccess(args, fn)\n      if (newBehavior === 'file-broken') fileBroken(args, fn)\n      if (newBehavior === 'file-error') fileError(args, fn)\n      if (newBehavior === 'dir-success') dirSuccess(args, fn)\n      if (newBehavior === 'dir-broken') dirBroken(args, fn)\n      if (newBehavior === 'dir-error') dirError(args, fn)\n    })\n  })\n\n  describe('ensureSymlink() promise support', () => {\n    tests.filter(test => test[2] === 'file-success').forEach(test => {\n      const args = test[0]\n      const srcpath = args[0]\n      const dstpath = args[1]\n      it(`should create symlink file using src ${srcpath} and dst ${dstpath}`, () => {\n        return ensureSymlink(srcpath, dstpath)\n          .then(() => {\n            const relative = symlinkPathsSync(srcpath, dstpath)\n            const srcContent = fs.readFileSync(relative.toCwd, 'utf8')\n            const dstDir = path.dirname(dstpath)\n            const dstBasename = path.basename(dstpath)\n            const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()\n            const dstContent = fs.readFileSync(dstpath, 'utf8')\n            const dstDirContents = fs.readdirSync(dstDir)\n            assert.strictEqual(isSymlink, true)\n            assert.strictEqual(srcContent, dstContent)\n            assert(dstDirContents.indexOf(dstBasename) >= 0)\n          })\n      })\n    })\n  })\n\n  describe('ensureSymlinkSync()', () => {\n    const fn = ensureSymlinkSync\n    tests.forEach(test => {\n      const args = test[0]\n      // const nativeBehavior = test[1]\n      const newBehavior = test[2]\n      if (newBehavior === 'file-success') fileSuccessSync(args, fn)\n      if (newBehavior === 'file-broken') fileBrokenSync(args, fn)\n      if (newBehavior === 'file-error') fileErrorSync(args, fn)\n      if (newBehavior === 'dir-success') dirSuccessSync(args, fn)\n      if (newBehavior === 'dir-broken') dirBrokenSync(args, fn)\n      if (newBehavior === 'dir-error') dirErrorSync(args, fn)\n    })\n  })\n\n  // https://github.com/jprichardson/node-fs-extra/issues/1038\n  describe('ensureSymlink() with relative path called twice (issue #1038)', () => {\n    it('should succeed when calling ensureSymlink twice with a relative path', async () => {\n      const targetDir = path.join(TEST_DIR, 'target-1038')\n      const linkDir = path.join(TEST_DIR, 'link-1038')\n      const linkPath = path.join(linkDir, 'link')\n      const relativeTarget = path.relative(linkDir, targetDir)\n\n      // Create target directory with a file\n      await fse.ensureDir(targetDir)\n      fs.writeFileSync(path.join(targetDir, 'file.txt'), 'content')\n\n      // First ensureSymlink call with relative path - should succeed\n      await ensureSymlink(relativeTarget, linkPath, 'dir')\n      assert.strictEqual(fs.lstatSync(linkPath).isSymbolicLink(), true)\n\n      // Second ensureSymlink call with same relative path - should also succeed\n      await ensureSymlink(relativeTarget, linkPath, 'dir')\n      assert.strictEqual(fs.lstatSync(linkPath).isSymbolicLink(), true)\n\n      // Verify the symlink still works\n      const content = fs.readFileSync(path.join(linkPath, 'file.txt'), 'utf8')\n      assert.strictEqual(content, 'content')\n    })\n\n    it('should succeed when calling ensureSymlinkSync twice with a relative path', () => {\n      const targetDir = path.join(TEST_DIR, 'target-1038-sync')\n      const linkDir = path.join(TEST_DIR, 'link-1038-sync')\n      const linkPath = path.join(linkDir, 'link')\n      const relativeTarget = path.relative(linkDir, targetDir)\n\n      // Create target directory with a file\n      fse.ensureDirSync(targetDir)\n      fs.writeFileSync(path.join(targetDir, 'file.txt'), 'content')\n\n      // First ensureSymlinkSync call with relative path - should succeed\n      ensureSymlinkSync(relativeTarget, linkPath, 'dir')\n      assert.strictEqual(fs.lstatSync(linkPath).isSymbolicLink(), true)\n\n      // Second ensureSymlinkSync call with same relative path - should also succeed\n      ensureSymlinkSync(relativeTarget, linkPath, 'dir')\n      assert.strictEqual(fs.lstatSync(linkPath).isSymbolicLink(), true)\n\n      // Verify the symlink still works\n      const content = fs.readFileSync(path.join(linkPath, 'file.txt'), 'utf8')\n      assert.strictEqual(content, 'content')\n    })\n  })\n})\n"
  },
  {
    "path": "lib/ensure/file.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nconst path = require('path')\nconst fs = require('../fs')\nconst mkdir = require('../mkdirs')\n\nasync function createFile (file) {\n  let stats\n  try {\n    stats = await fs.stat(file)\n  } catch { }\n  if (stats && stats.isFile()) return\n\n  const dir = path.dirname(file)\n\n  let dirStats = null\n  try {\n    dirStats = await fs.stat(dir)\n  } catch (err) {\n    // if the directory doesn't exist, make it\n    if (err.code === 'ENOENT') {\n      await mkdir.mkdirs(dir)\n      await fs.writeFile(file, '')\n      return\n    } else {\n      throw err\n    }\n  }\n\n  if (dirStats.isDirectory()) {\n    await fs.writeFile(file, '')\n  } else {\n    // parent is not a directory\n    // This is just to cause an internal ENOTDIR error to be thrown\n    await fs.readdir(dir)\n  }\n}\n\nfunction createFileSync (file) {\n  let stats\n  try {\n    stats = fs.statSync(file)\n  } catch { }\n  if (stats && stats.isFile()) return\n\n  const dir = path.dirname(file)\n  try {\n    if (!fs.statSync(dir).isDirectory()) {\n      // parent is not a directory\n      // This is just to cause an internal ENOTDIR error to be thrown\n      fs.readdirSync(dir)\n    }\n  } catch (err) {\n    // If the stat call above failed because the directory doesn't exist, create it\n    if (err && err.code === 'ENOENT') mkdir.mkdirsSync(dir)\n    else throw err\n  }\n\n  fs.writeFileSync(file, '')\n}\n\nmodule.exports = {\n  createFile: u(createFile),\n  createFileSync\n}\n"
  },
  {
    "path": "lib/ensure/index.js",
    "content": "'use strict'\n\nconst { createFile, createFileSync } = require('./file')\nconst { createLink, createLinkSync } = require('./link')\nconst { createSymlink, createSymlinkSync } = require('./symlink')\n\nmodule.exports = {\n  // file\n  createFile,\n  createFileSync,\n  ensureFile: createFile,\n  ensureFileSync: createFileSync,\n  // link\n  createLink,\n  createLinkSync,\n  ensureLink: createLink,\n  ensureLinkSync: createLinkSync,\n  // symlink\n  createSymlink,\n  createSymlinkSync,\n  ensureSymlink: createSymlink,\n  ensureSymlinkSync: createSymlinkSync\n}\n"
  },
  {
    "path": "lib/ensure/link.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nconst path = require('path')\nconst fs = require('../fs')\nconst mkdir = require('../mkdirs')\nconst { pathExists } = require('../path-exists')\nconst { areIdentical } = require('../util/stat')\n\nasync function createLink (srcpath, dstpath) {\n  let dstStat\n  try {\n    dstStat = await fs.lstat(dstpath)\n  } catch {\n    // ignore error\n  }\n\n  let srcStat\n  try {\n    srcStat = await fs.lstat(srcpath)\n  } catch (err) {\n    err.message = err.message.replace('lstat', 'ensureLink')\n    throw err\n  }\n\n  if (dstStat && areIdentical(srcStat, dstStat)) return\n\n  const dir = path.dirname(dstpath)\n\n  const dirExists = await pathExists(dir)\n\n  if (!dirExists) {\n    await mkdir.mkdirs(dir)\n  }\n\n  await fs.link(srcpath, dstpath)\n}\n\nfunction createLinkSync (srcpath, dstpath) {\n  let dstStat\n  try {\n    dstStat = fs.lstatSync(dstpath)\n  } catch {}\n\n  try {\n    const srcStat = fs.lstatSync(srcpath)\n    if (dstStat && areIdentical(srcStat, dstStat)) return\n  } catch (err) {\n    err.message = err.message.replace('lstat', 'ensureLink')\n    throw err\n  }\n\n  const dir = path.dirname(dstpath)\n  const dirExists = fs.existsSync(dir)\n  if (dirExists) return fs.linkSync(srcpath, dstpath)\n  mkdir.mkdirsSync(dir)\n\n  return fs.linkSync(srcpath, dstpath)\n}\n\nmodule.exports = {\n  createLink: u(createLink),\n  createLinkSync\n}\n"
  },
  {
    "path": "lib/ensure/symlink-paths.js",
    "content": "'use strict'\n\nconst path = require('path')\nconst fs = require('../fs')\nconst { pathExists } = require('../path-exists')\n\nconst u = require('universalify').fromPromise\n\n/**\n * Function that returns two types of paths, one relative to symlink, and one\n * relative to the current working directory. Checks if path is absolute or\n * relative. If the path is relative, this function checks if the path is\n * relative to symlink or relative to current working directory. This is an\n * initiative to find a smarter `srcpath` to supply when building symlinks.\n * This allows you to determine which path to use out of one of three possible\n * types of source paths. The first is an absolute path. This is detected by\n * `path.isAbsolute()`. When an absolute path is provided, it is checked to\n * see if it exists. If it does it's used, if not an error is returned\n * (callback)/ thrown (sync). The other two options for `srcpath` are a\n * relative url. By default Node's `fs.symlink` works by creating a symlink\n * using `dstpath` and expects the `srcpath` to be relative to the newly\n * created symlink. If you provide a `srcpath` that does not exist on the file\n * system it results in a broken symlink. To minimize this, the function\n * checks to see if the 'relative to symlink' source file exists, and if it\n * does it will use it. If it does not, it checks if there's a file that\n * exists that is relative to the current working directory, if does its used.\n * This preserves the expectations of the original fs.symlink spec and adds\n * the ability to pass in `relative to current working direcotry` paths.\n */\n\nasync function symlinkPaths (srcpath, dstpath) {\n  if (path.isAbsolute(srcpath)) {\n    try {\n      await fs.lstat(srcpath)\n    } catch (err) {\n      err.message = err.message.replace('lstat', 'ensureSymlink')\n      throw err\n    }\n\n    return {\n      toCwd: srcpath,\n      toDst: srcpath\n    }\n  }\n\n  const dstdir = path.dirname(dstpath)\n  const relativeToDst = path.join(dstdir, srcpath)\n\n  const exists = await pathExists(relativeToDst)\n  if (exists) {\n    return {\n      toCwd: relativeToDst,\n      toDst: srcpath\n    }\n  }\n\n  try {\n    await fs.lstat(srcpath)\n  } catch (err) {\n    err.message = err.message.replace('lstat', 'ensureSymlink')\n    throw err\n  }\n\n  return {\n    toCwd: srcpath,\n    toDst: path.relative(dstdir, srcpath)\n  }\n}\n\nfunction symlinkPathsSync (srcpath, dstpath) {\n  if (path.isAbsolute(srcpath)) {\n    const exists = fs.existsSync(srcpath)\n    if (!exists) throw new Error('absolute srcpath does not exist')\n    return {\n      toCwd: srcpath,\n      toDst: srcpath\n    }\n  }\n\n  const dstdir = path.dirname(dstpath)\n  const relativeToDst = path.join(dstdir, srcpath)\n  const exists = fs.existsSync(relativeToDst)\n  if (exists) {\n    return {\n      toCwd: relativeToDst,\n      toDst: srcpath\n    }\n  }\n\n  const srcExists = fs.existsSync(srcpath)\n  if (!srcExists) throw new Error('relative srcpath does not exist')\n  return {\n    toCwd: srcpath,\n    toDst: path.relative(dstdir, srcpath)\n  }\n}\n\nmodule.exports = {\n  symlinkPaths: u(symlinkPaths),\n  symlinkPathsSync\n}\n"
  },
  {
    "path": "lib/ensure/symlink-type.js",
    "content": "'use strict'\n\nconst fs = require('../fs')\nconst u = require('universalify').fromPromise\n\nasync function symlinkType (srcpath, type) {\n  if (type) return type\n\n  let stats\n  try {\n    stats = await fs.lstat(srcpath)\n  } catch {\n    return 'file'\n  }\n\n  return (stats && stats.isDirectory()) ? 'dir' : 'file'\n}\n\nfunction symlinkTypeSync (srcpath, type) {\n  if (type) return type\n\n  let stats\n  try {\n    stats = fs.lstatSync(srcpath)\n  } catch {\n    return 'file'\n  }\n  return (stats && stats.isDirectory()) ? 'dir' : 'file'\n}\n\nmodule.exports = {\n  symlinkType: u(symlinkType),\n  symlinkTypeSync\n}\n"
  },
  {
    "path": "lib/ensure/symlink.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nconst path = require('path')\nconst fs = require('../fs')\n\nconst { mkdirs, mkdirsSync } = require('../mkdirs')\n\nconst { symlinkPaths, symlinkPathsSync } = require('./symlink-paths')\nconst { symlinkType, symlinkTypeSync } = require('./symlink-type')\n\nconst { pathExists } = require('../path-exists')\n\nconst { areIdentical } = require('../util/stat')\n\nasync function createSymlink (srcpath, dstpath, type) {\n  let stats\n  try {\n    stats = await fs.lstat(dstpath)\n  } catch { }\n\n  if (stats && stats.isSymbolicLink()) {\n    // When srcpath is relative, resolve it relative to dstpath's directory\n    // (standard symlink behavior) or fall back to cwd if that doesn't exist\n    let srcStat\n    if (path.isAbsolute(srcpath)) {\n      srcStat = await fs.stat(srcpath)\n    } else {\n      const dstdir = path.dirname(dstpath)\n      const relativeToDst = path.join(dstdir, srcpath)\n      try {\n        srcStat = await fs.stat(relativeToDst)\n      } catch {\n        srcStat = await fs.stat(srcpath)\n      }\n    }\n\n    const dstStat = await fs.stat(dstpath)\n    if (areIdentical(srcStat, dstStat)) return\n  }\n\n  const relative = await symlinkPaths(srcpath, dstpath)\n  srcpath = relative.toDst\n  const toType = await symlinkType(relative.toCwd, type)\n  const dir = path.dirname(dstpath)\n\n  if (!(await pathExists(dir))) {\n    await mkdirs(dir)\n  }\n\n  return fs.symlink(srcpath, dstpath, toType)\n}\n\nfunction createSymlinkSync (srcpath, dstpath, type) {\n  let stats\n  try {\n    stats = fs.lstatSync(dstpath)\n  } catch { }\n  if (stats && stats.isSymbolicLink()) {\n    // When srcpath is relative, resolve it relative to dstpath's directory\n    // (standard symlink behavior) or fall back to cwd if that doesn't exist\n    let srcStat\n    if (path.isAbsolute(srcpath)) {\n      srcStat = fs.statSync(srcpath)\n    } else {\n      const dstdir = path.dirname(dstpath)\n      const relativeToDst = path.join(dstdir, srcpath)\n      try {\n        srcStat = fs.statSync(relativeToDst)\n      } catch {\n        srcStat = fs.statSync(srcpath)\n      }\n    }\n\n    const dstStat = fs.statSync(dstpath)\n    if (areIdentical(srcStat, dstStat)) return\n  }\n\n  const relative = symlinkPathsSync(srcpath, dstpath)\n  srcpath = relative.toDst\n  type = symlinkTypeSync(relative.toCwd, type)\n  const dir = path.dirname(dstpath)\n  const exists = fs.existsSync(dir)\n  if (exists) return fs.symlinkSync(srcpath, dstpath, type)\n  mkdirsSync(dir)\n  return fs.symlinkSync(srcpath, dstpath, type)\n}\n\nmodule.exports = {\n  createSymlink: u(createSymlink),\n  createSymlinkSync\n}\n"
  },
  {
    "path": "lib/esm.mjs",
    "content": "import _copy from './copy/index.js'\nimport _empty from './empty/index.js'\nimport _ensure from './ensure/index.js'\nimport _json from './json/index.js'\nimport _mkdirs from './mkdirs/index.js'\nimport _move from './move/index.js'\nimport _outputFile from './output-file/index.js'\nimport _pathExists from './path-exists/index.js'\nimport _remove from './remove/index.js'\n\n// NOTE: Only exports fs-extra's functions; fs functions must be imported from \"node:fs\" or \"node:fs/promises\"\n\nexport const copy = _copy.copy\nexport const copySync = _copy.copySync\nexport const emptyDirSync = _empty.emptyDirSync\nexport const emptydirSync = _empty.emptydirSync\nexport const emptyDir = _empty.emptyDir\nexport const emptydir = _empty.emptydir\nexport const createFile = _ensure.createFile\nexport const createFileSync = _ensure.createFileSync\nexport const ensureFile = _ensure.ensureFile\nexport const ensureFileSync = _ensure.ensureFileSync\nexport const createLink = _ensure.createLink\nexport const createLinkSync = _ensure.createLinkSync\nexport const ensureLink = _ensure.ensureLink\nexport const ensureLinkSync = _ensure.ensureLinkSync\nexport const createSymlink = _ensure.createSymlink\nexport const createSymlinkSync = _ensure.createSymlinkSync\nexport const ensureSymlink = _ensure.ensureSymlink\nexport const ensureSymlinkSync = _ensure.ensureSymlinkSync\nexport const readJson = _json.readJson\nexport const readJSON = _json.readJSON\nexport const readJsonSync = _json.readJsonSync\nexport const readJSONSync = _json.readJSONSync\nexport const writeJson = _json.writeJson\nexport const writeJSON = _json.writeJSON\nexport const writeJsonSync = _json.writeJsonSync\nexport const writeJSONSync = _json.writeJSONSync\nexport const outputJson = _json.outputJson\nexport const outputJSON = _json.outputJSON\nexport const outputJsonSync = _json.outputJsonSync\nexport const outputJSONSync = _json.outputJSONSync\nexport const mkdirs = _mkdirs.mkdirs\nexport const mkdirsSync = _mkdirs.mkdirsSync\nexport const mkdirp = _mkdirs.mkdirp\nexport const mkdirpSync = _mkdirs.mkdirpSync\nexport const ensureDir = _mkdirs.ensureDir\nexport const ensureDirSync = _mkdirs.ensureDirSync\nexport const move = _move.move\nexport const moveSync = _move.moveSync\nexport const outputFile = _outputFile.outputFile\nexport const outputFileSync = _outputFile.outputFileSync\nexport const pathExists = _pathExists.pathExists\nexport const pathExistsSync = _pathExists.pathExistsSync\nexport const remove = _remove.remove\nexport const removeSync = _remove.removeSync\n\nexport default {\n  ..._copy,\n  ..._empty,\n  ..._ensure,\n  ..._json,\n  ..._mkdirs,\n  ..._move,\n  ..._outputFile,\n  ..._pathExists,\n  ..._remove\n}\n"
  },
  {
    "path": "lib/fs/__tests__/copyFile.test.js",
    "content": "'use strict'\n\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* eslint-env mocha */\n\ndescribe('fs.copyFile', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'fs-copyfile')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('supports promises', () => {\n    const src = path.join(TEST_DIR, 'init.txt')\n    const dest = path.join(TEST_DIR, 'copy.txt')\n    fse.writeFileSync(src, 'hello')\n    return fse.copyFile(src, dest).then(() => {\n      const data = fse.readFileSync(dest, 'utf8')\n      assert.strictEqual(data, 'hello')\n    })\n  })\n})\n"
  },
  {
    "path": "lib/fs/__tests__/fs-integration.test.js",
    "content": "'use strict'\n\nconst os = require('os')\nconst fs = require('fs')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('native fs', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'native-fs')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('should use native fs methods', () => {\n    const file = path.join(TEST_DIR, 'write.txt')\n    fse.writeFileSync(file, 'hello')\n    const data = fse.readFileSync(file, 'utf8')\n    assert.strictEqual(data, 'hello')\n  })\n\n  it('should have native fs constants', () => {\n    assert.strictEqual(fse.constants.F_OK, fs.constants.F_OK)\n  })\n})\n"
  },
  {
    "path": "lib/fs/__tests__/multi-param.test.js",
    "content": "'use strict'\n/* eslint-env mocha */\nconst assert = require('assert')\nconst path = require('path')\nconst crypto = require('crypto')\nconst os = require('os')\nconst fs = require('../..')\n\nconst SIZE = 1000\n\ndescribe('fs.read()', () => {\n  let TEST_FILE\n  let TEST_DATA\n  let TEST_FD\n\n  beforeEach(() => {\n    TEST_FILE = path.join(os.tmpdir(), 'fs-extra', 'read-test-file')\n    TEST_DATA = crypto.randomBytes(SIZE)\n    fs.writeFileSync(TEST_FILE, TEST_DATA)\n    TEST_FD = fs.openSync(TEST_FILE, 'r')\n  })\n\n  afterEach(() => {\n    return fs.close(TEST_FD)\n      .then(() => fs.remove(TEST_FILE))\n  })\n\n  describe('with promises', () => {\n    it('returns an object', () => {\n      return fs.read(TEST_FD, Buffer.alloc(SIZE), 0, SIZE, 0)\n        .then(results => {\n          const bytesRead = results.bytesRead\n          const buffer = results.buffer\n          assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n          assert(buffer.equals(TEST_DATA), 'data is correct')\n        })\n    })\n\n    it('returns an object when position is not set', () => {\n      return fs.read(TEST_FD, Buffer.alloc(SIZE), 0, SIZE)\n        .then(results => {\n          const bytesRead = results.bytesRead\n          const buffer = results.buffer\n          assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n          assert(buffer.equals(TEST_DATA), 'data is correct')\n        })\n    })\n  })\n\n  describe('with callbacks', () => {\n    it('works', done => {\n      fs.read(TEST_FD, Buffer.alloc(SIZE), 0, SIZE, 0, (err, bytesRead, buffer) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n        assert(buffer.equals(TEST_DATA), 'data is correct')\n        done()\n      })\n    })\n\n    it('works when position is null', done => {\n      fs.read(TEST_FD, Buffer.alloc(SIZE), 0, SIZE, null, (err, bytesRead, buffer) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n        assert(buffer.equals(TEST_DATA), 'data is correct')\n        done()\n      })\n    })\n  })\n})\n\ndescribe('fs.write()', () => {\n  let TEST_FILE\n  let TEST_DATA\n  let TEST_FD\n\n  beforeEach(() => {\n    TEST_FILE = path.join(os.tmpdir(), 'fs-extra', 'write-test-file')\n    TEST_DATA = crypto.randomBytes(SIZE)\n    fs.ensureDirSync(path.dirname(TEST_FILE))\n    TEST_FD = fs.openSync(TEST_FILE, 'w')\n  })\n\n  afterEach(() => {\n    return fs.close(TEST_FD)\n      .then(() => fs.remove(TEST_FILE))\n  })\n\n  describe('with promises', () => {\n    it('returns an object', () => {\n      return fs.write(TEST_FD, TEST_DATA, 0, SIZE, 0)\n        .then(results => {\n          const bytesWritten = results.bytesWritten\n          const buffer = results.buffer\n          assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n          assert(buffer.equals(TEST_DATA), 'data is correct')\n        })\n    })\n\n    it('returns an object when minimal arguments are passed', () => {\n      return fs.write(TEST_FD, TEST_DATA)\n        .then(results => {\n          const bytesWritten = results.bytesWritten\n          const buffer = results.buffer\n          assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n          assert(buffer.equals(TEST_DATA), 'data is correct')\n        })\n    })\n\n    it('returns an object when writing a string', () => {\n      const message = 'Hello World!'\n      return fs.write(TEST_FD, message)\n        .then(results => {\n          const bytesWritten = results.bytesWritten\n          const buffer = results.buffer\n          assert.strictEqual(bytesWritten, message.length, 'bytesWritten is correct')\n          assert.strictEqual(buffer, message, 'data is correct')\n        })\n    })\n  })\n\n  describe('with callbacks', () => {\n    it('works', done => {\n      fs.write(TEST_FD, TEST_DATA, 0, SIZE, 0, (err, bytesWritten, buffer) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n        assert(buffer.equals(TEST_DATA), 'data is correct')\n        done()\n      })\n    })\n\n    it('works when minimal arguments are passed', done => {\n      fs.write(TEST_FD, TEST_DATA, (err, bytesWritten, buffer) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n        assert(buffer.equals(TEST_DATA), 'data is correct')\n        done()\n      })\n    })\n\n    it('works when writing a string', done => {\n      const message = 'Hello World!'\n      return fs.write(TEST_FD, message, (err, bytesWritten, buffer) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesWritten, message.length, 'bytesWritten is correct')\n        assert.strictEqual(buffer, message, 'data is correct')\n        done()\n      })\n    })\n  })\n})\n\ndescribe('fs.readv()', () => {\n  let TEST_FILE\n  let TEST_DATA\n  let TEST_FD\n\n  beforeEach(() => {\n    TEST_FILE = path.join(os.tmpdir(), 'fs-extra', 'readv-test-file')\n    TEST_DATA = crypto.randomBytes(SIZE)\n    fs.writeFileSync(TEST_FILE, TEST_DATA)\n    TEST_FD = fs.openSync(TEST_FILE, 'r')\n  })\n\n  afterEach(() => {\n    return fs.close(TEST_FD)\n      .then(() => fs.remove(TEST_FILE))\n  })\n\n  describe('with promises', () => {\n    it('returns an object', () => {\n      const bufferArray = [Buffer.alloc(SIZE / 2), Buffer.alloc(SIZE / 2)]\n      return fs.readv(TEST_FD, bufferArray, 0)\n        .then(({ bytesRead, buffers }) => {\n          assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n          assert.deepStrictEqual(buffers, bufferArray, 'returned data matches mutated input param')\n          assert.deepStrictEqual(Buffer.concat(buffers), TEST_DATA, 'data is correct')\n        })\n    })\n\n    it('returns an object when minimal arguments are passed', () => {\n      const bufferArray = [Buffer.alloc(SIZE / 2), Buffer.alloc(SIZE / 2)]\n      return fs.readv(TEST_FD, bufferArray)\n        .then(({ bytesRead, buffers }) => {\n          assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n          assert.deepStrictEqual(buffers, bufferArray, 'returned data matches mutated input param')\n          assert.deepStrictEqual(Buffer.concat(buffers), TEST_DATA, 'data is correct')\n        })\n    })\n  })\n\n  describe('with callbacks', () => {\n    it('works', done => {\n      const bufferArray = [Buffer.alloc(SIZE / 2), Buffer.alloc(SIZE / 2)]\n      fs.readv(TEST_FD, bufferArray, 0, (err, bytesRead, buffers) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n        assert.deepStrictEqual(buffers, bufferArray, 'returned data matches mutated input param')\n        assert.deepStrictEqual(Buffer.concat(buffers), TEST_DATA, 'data is correct')\n        done()\n      })\n    })\n\n    it('works when minimal arguments are passed', done => {\n      const bufferArray = [Buffer.alloc(SIZE / 2), Buffer.alloc(SIZE / 2)]\n      fs.readv(TEST_FD, bufferArray, (err, bytesRead, buffers) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesRead, SIZE, 'bytesRead is correct')\n        assert.deepStrictEqual(buffers, bufferArray, 'returned data matches mutated input param')\n        assert.deepStrictEqual(Buffer.concat(buffers), TEST_DATA, 'data is correct')\n        done()\n      })\n    })\n  })\n})\n\ndescribe('fs.writev()', () => {\n  let TEST_FILE\n  let TEST_DATA\n  let TEST_FD\n\n  beforeEach(() => {\n    TEST_FILE = path.join(os.tmpdir(), 'fs-extra', 'writev-test-file')\n    TEST_DATA = [crypto.randomBytes(SIZE / 2), crypto.randomBytes(SIZE / 2)]\n    fs.ensureDirSync(path.dirname(TEST_FILE))\n    TEST_FD = fs.openSync(TEST_FILE, 'w')\n  })\n\n  afterEach(() => {\n    return fs.close(TEST_FD)\n      .then(() => fs.remove(TEST_FILE))\n  })\n\n  describe('with promises', () => {\n    it('returns an object', () => {\n      return fs.writev(TEST_FD, TEST_DATA, 0)\n        .then(({ bytesWritten, buffers }) => {\n          assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n          assert.deepStrictEqual(buffers, TEST_DATA, 'data is correct')\n        })\n    })\n\n    it('returns an object when minimal arguments are passed', () => {\n      return fs.writev(TEST_FD, TEST_DATA)\n        .then(({ bytesWritten, buffers }) => {\n          assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n          assert.deepStrictEqual(buffers, TEST_DATA, 'data is correct')\n        })\n    })\n  })\n\n  describe('with callbacks', () => {\n    it('works', done => {\n      fs.writev(TEST_FD, TEST_DATA, 0, (err, bytesWritten, buffers) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n        assert.deepStrictEqual(buffers, TEST_DATA, 'data is correct')\n        done()\n      })\n    })\n\n    it('works when minimal arguments are passed', done => {\n      fs.writev(TEST_FD, TEST_DATA, (err, bytesWritten, buffers) => {\n        assert.ifError(err)\n        assert.strictEqual(bytesWritten, SIZE, 'bytesWritten is correct')\n        assert.deepStrictEqual(buffers, TEST_DATA, 'data is correct')\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/fs/__tests__/mz.test.js",
    "content": "'use strict'\n// This is adapted from https://github.com/normalize/mz\n// Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors\n\n/* eslint-env mocha */\nconst assert = require('assert')\nconst fs = require('../..')\n\ndescribe('fs', () => {\n  it('.stat()', done => {\n    fs.stat(__filename).then(stats => {\n      assert.strictEqual(typeof stats.size, 'number')\n      done()\n    }).catch(done)\n  })\n\n  it('.statSync()', () => {\n    const stats = fs.statSync(__filename)\n    assert.strictEqual(typeof stats.size, 'number')\n  })\n\n  it('.exists()', done => {\n    fs.exists(__filename).then(exists => {\n      assert(exists)\n      done()\n    }).catch(done)\n  })\n\n  it('.existsSync()', () => {\n    const exists = fs.existsSync(__filename)\n    assert(exists)\n  })\n\n  describe('callback support', () => {\n    it('.stat()', done => {\n      fs.stat(__filename, (err, stats) => {\n        assert(!err)\n        assert.strictEqual(typeof stats.size, 'number')\n        done()\n      })\n    })\n\n    // This test is different from mz/fs, since we are a drop-in replacement for native fs\n    it('.exists()', done => {\n      fs.exists(__filename, exists => {\n        assert(exists)\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/fs/__tests__/realpath.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst path = require('path')\nconst assert = require('assert')\n\n/* eslint-env mocha */\n\ndescribe('realpath.native does not exist', () => {\n  let warning\n  const warningListener = error => {\n    if (error.name === 'Warning') {\n      if (error.code.startsWith('fs-extra-WARN0003')) {\n        warning = error\n      }\n    }\n  }\n\n  const realpathNativeBackup = fs.realpath.native\n  const clearFseCache = () => {\n    const fsePath = path.dirname(require.resolve('../..'))\n    for (const entry in require.cache) {\n      if (entry.startsWith(fsePath)) {\n        delete require.cache[entry]\n      }\n    }\n  }\n\n  before(() => {\n    process.on('warning', warningListener)\n\n    // clear existing require.cache\n    clearFseCache()\n\n    // simulate fs monkey-patch\n    delete fs.realpath.native\n  })\n\n  after(() => {\n    process.off('warning', warningListener)\n\n    // clear stubbed require.cache\n    clearFseCache()\n\n    // reinstate fs.realpath.native\n    fs.realpath.native = realpathNativeBackup\n  })\n\n  it('fse should not export realpath.native', done => {\n    const fse = require('../..')\n\n    // next event loop to allow event emitter/listener to happen\n    setImmediate(() => {\n      assert(warning, 'fs-extra-WARN0003 should be emitted')\n      done()\n    })\n\n    assert(!fse.realpath.native)\n  })\n})\n\ndescribe('realpath.native', () => {\n  const fse = require('../..')\n\n  it('works with callbacks', () => {\n    fse.realpath.native(__dirname, (err, path) => {\n      assert.ifError(err)\n      assert.strictEqual(path, __dirname)\n    })\n  })\n\n  it('works with promises', (done) => {\n    fse.realpath.native(__dirname)\n      .then(path => {\n        assert.strictEqual(path, __dirname)\n        done()\n      })\n      .catch(done)\n  })\n\n  it('works with sync version', () => {\n    const path = fse.realpathSync.native(__dirname)\n    assert.strictEqual(path, __dirname)\n  })\n})\n"
  },
  {
    "path": "lib/fs/__tests__/rm.test.js",
    "content": "'use strict'\n\nconst fse = require('../..')\nconst os = require('os')\nconst path = require('path')\nconst assert = require('assert')\n\n/* eslint-env mocha */\n\ndescribe('fs.rm', () => {\n  let TEST_FILE\n\n  beforeEach(done => {\n    TEST_FILE = path.join(os.tmpdir(), 'fs-extra', 'fs-rm')\n    fse.remove(TEST_FILE, done)\n  })\n\n  afterEach(done => fse.remove(TEST_FILE, done))\n\n  it('supports promises', () => {\n    fse.writeFileSync(TEST_FILE, 'hello')\n    return fse.rm(TEST_FILE).then(() => {\n      assert(!fse.pathExistsSync(TEST_FILE))\n    })\n  })\n})\n"
  },
  {
    "path": "lib/fs/index.js",
    "content": "'use strict'\n// This is adapted from https://github.com/normalize/mz\n// Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors\nconst u = require('universalify').fromCallback\nconst fs = require('graceful-fs')\n\nconst api = [\n  'access',\n  'appendFile',\n  'chmod',\n  'chown',\n  'close',\n  'copyFile',\n  'cp',\n  'fchmod',\n  'fchown',\n  'fdatasync',\n  'fstat',\n  'fsync',\n  'ftruncate',\n  'futimes',\n  'glob',\n  'lchmod',\n  'lchown',\n  'lutimes',\n  'link',\n  'lstat',\n  'mkdir',\n  'mkdtemp',\n  'open',\n  'opendir',\n  'readdir',\n  'readFile',\n  'readlink',\n  'realpath',\n  'rename',\n  'rm',\n  'rmdir',\n  'stat',\n  'statfs',\n  'symlink',\n  'truncate',\n  'unlink',\n  'utimes',\n  'writeFile'\n].filter(key => {\n  // Some commands are not available on some systems. Ex:\n  // fs.cp was added in Node.js v16.7.0\n  // fs.statfs was added in Node v19.6.0, v18.15.0\n  // fs.glob was added in Node.js v22.0.0\n  // fs.lchown is not available on at least some Linux\n  return typeof fs[key] === 'function'\n})\n\n// Export cloned fs:\nObject.assign(exports, fs)\n\n// Universalify async methods:\napi.forEach(method => {\n  exports[method] = u(fs[method])\n})\n\n// We differ from mz/fs in that we still ship the old, broken, fs.exists()\n// since we are a drop-in replacement for the native module\nexports.exists = function (filename, callback) {\n  if (typeof callback === 'function') {\n    return fs.exists(filename, callback)\n  }\n  return new Promise(resolve => {\n    return fs.exists(filename, resolve)\n  })\n}\n\n// fs.read(), fs.write(), fs.readv(), & fs.writev() need special treatment due to multiple callback args\n\nexports.read = function (fd, buffer, offset, length, position, callback) {\n  if (typeof callback === 'function') {\n    return fs.read(fd, buffer, offset, length, position, callback)\n  }\n  return new Promise((resolve, reject) => {\n    fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {\n      if (err) return reject(err)\n      resolve({ bytesRead, buffer })\n    })\n  })\n}\n\n// Function signature can be\n// fs.write(fd, buffer[, offset[, length[, position]]], callback)\n// OR\n// fs.write(fd, string[, position[, encoding]], callback)\n// We need to handle both cases, so we use ...args\nexports.write = function (fd, buffer, ...args) {\n  if (typeof args[args.length - 1] === 'function') {\n    return fs.write(fd, buffer, ...args)\n  }\n\n  return new Promise((resolve, reject) => {\n    fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {\n      if (err) return reject(err)\n      resolve({ bytesWritten, buffer })\n    })\n  })\n}\n\n// Function signature is\n// s.readv(fd, buffers[, position], callback)\n// We need to handle the optional arg, so we use ...args\nexports.readv = function (fd, buffers, ...args) {\n  if (typeof args[args.length - 1] === 'function') {\n    return fs.readv(fd, buffers, ...args)\n  }\n\n  return new Promise((resolve, reject) => {\n    fs.readv(fd, buffers, ...args, (err, bytesRead, buffers) => {\n      if (err) return reject(err)\n      resolve({ bytesRead, buffers })\n    })\n  })\n}\n\n// Function signature is\n// s.writev(fd, buffers[, position], callback)\n// We need to handle the optional arg, so we use ...args\nexports.writev = function (fd, buffers, ...args) {\n  if (typeof args[args.length - 1] === 'function') {\n    return fs.writev(fd, buffers, ...args)\n  }\n\n  return new Promise((resolve, reject) => {\n    fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => {\n      if (err) return reject(err)\n      resolve({ bytesWritten, buffers })\n    })\n  })\n}\n\n// fs.realpath.native sometimes not available if fs is monkey-patched\nif (typeof fs.realpath.native === 'function') {\n  exports.realpath.native = u(fs.realpath.native)\n} else {\n  process.emitWarning(\n    'fs.realpath.native is not a function. Is fs being monkey-patched?',\n    'Warning', 'fs-extra-WARN0003'\n  )\n}\n"
  },
  {
    "path": "lib/index.js",
    "content": "'use strict'\n\nmodule.exports = {\n  // Export promiseified graceful-fs:\n  ...require('./fs'),\n  // Export extra methods:\n  ...require('./copy'),\n  ...require('./empty'),\n  ...require('./ensure'),\n  ...require('./json'),\n  ...require('./mkdirs'),\n  ...require('./move'),\n  ...require('./output-file'),\n  ...require('./path-exists'),\n  ...require('./remove')\n}\n"
  },
  {
    "path": "lib/json/__tests__/jsonfile-integration.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('jsonfile-integration', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'json')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ writeJsonSync / spaces', () => {\n    it('should read a file and parse the json', () => {\n      const obj1 = {\n        firstName: 'JP',\n        lastName: 'Richardson'\n      }\n\n      const file = path.join(TEST_DIR, 'file.json')\n      fse.writeJsonSync(file, obj1)\n      const data = fs.readFileSync(file, 'utf8')\n      assert.strictEqual(data, JSON.stringify(obj1) + '\\n')\n    })\n  })\n\n  describe('+ writeJsonSync / EOL', () => {\n    it('should read a file and parse the json', () => {\n      const obj1 = {\n        firstName: 'JP',\n        lastName: 'Richardson'\n      }\n\n      const file = path.join(TEST_DIR, 'file.json')\n      fse.writeJsonSync(file, obj1, { spaces: 2, EOL: '\\r\\n' })\n      const data = fs.readFileSync(file, 'utf8')\n      assert.strictEqual(\n        data,\n        JSON.stringify(obj1, null, 2).replace(/\\n/g, '\\r\\n') + '\\r\\n'\n      )\n    })\n  })\n})\n"
  },
  {
    "path": "lib/json/__tests__/output-json-sync.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global beforeEach, describe, it */\n\ndescribe('json', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra-output-json-sync')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  describe('+ outputJsonSync(file, data)', () => {\n    it('should write the file regardless of whether the directory exists or not', () => {\n      const file = path.join(TEST_DIR, 'this-dir', 'does-not', 'exist', 'file.json')\n      assert(!fs.existsSync(file))\n\n      const data = { name: 'JP' }\n      fse.outputJsonSync(file, data)\n\n      assert(fs.existsSync(file))\n      const newData = JSON.parse(fs.readFileSync(file, 'utf8'))\n\n      assert.strictEqual(data.name, newData.name)\n    })\n\n    describe('> when an option is passed, like JSON replacer', () => {\n      it('should pass the option along to jsonfile module', () => {\n        const file = path.join(TEST_DIR, 'this-dir', 'does-not', 'exist', 'really', 'file.json')\n        assert(!fs.existsSync(file))\n\n        const replacer = (k, v) => v === 'JP' ? 'Jon Paul' : v\n        const data = { name: 'JP' }\n\n        fse.outputJsonSync(file, data, { replacer })\n        const newData = JSON.parse(fs.readFileSync(file, 'utf8'))\n\n        assert.strictEqual(newData.name, 'Jon Paul')\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/json/__tests__/output-json.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global beforeEach, describe, it */\n\ndescribe('json', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra-output-json')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  describe('+ outputJson(file, data)', () => {\n    it('should write the file regardless of whether the directory exists or not', done => {\n      const file = path.join(TEST_DIR, 'this-dir', 'prob-does-not', 'exist', 'file.json')\n      assert(!fs.existsSync(file))\n\n      const data = { name: 'JP' }\n      fse.outputJson(file, data, err => {\n        if (err) return done(err)\n\n        assert(fs.existsSync(file))\n        const newData = JSON.parse(fs.readFileSync(file, 'utf8'))\n\n        assert.strictEqual(data.name, newData.name)\n        done()\n      })\n    })\n\n    it('should be mutation-proof', async () => {\n      const dir = path.join(TEST_DIR, 'this-dir', 'certanly-does-not', 'exist')\n      const file = path.join(dir, 'file.json')\n      assert(!fs.existsSync(dir), 'directory cannot exist')\n\n      const name = 'JP'\n      const data = { name }\n      const promise = fse.outputJson(file, data)\n      // Mutate data right after call\n      data.name = 'Ryan'\n      // now await for the call to finish\n      await promise\n\n      assert(fs.existsSync(file))\n      const newData = JSON.parse(fs.readFileSync(file, 'utf8'))\n\n      // mutation did not change data\n      assert.strictEqual(newData.name, name)\n    })\n\n    it('should support Promises', () => {\n      const file = path.join(TEST_DIR, 'this-dir', 'prob-does-not', 'exist', 'file.json')\n      assert(!fs.existsSync(file))\n\n      const data = { name: 'JP' }\n      return fse.outputJson(file, data)\n    })\n\n    describe('> when an option is passed, like JSON replacer', () => {\n      it('should pass the option along to jsonfile module', done => {\n        const file = path.join(TEST_DIR, 'this-dir', 'does-not', 'exist', 'really', 'file.json')\n        assert(!fs.existsSync(file))\n\n        const replacer = (k, v) => v === 'JP' ? 'Jon Paul' : v\n        const data = { name: 'JP' }\n\n        fse.outputJson(file, data, { replacer }, err => {\n          assert.ifError(err)\n          const newData = JSON.parse(fs.readFileSync(file, 'utf8'))\n          assert.strictEqual(newData.name, 'Jon Paul')\n          done()\n        })\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/json/__tests__/promise-support.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('json promise support', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'json')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  ;['writeJson', 'writeJSON'].forEach(method => {\n    describe(method, () => {\n      it('should support promises', () => {\n        const obj1 = {\n          firstName: 'JP',\n          lastName: 'Richardson'\n        }\n\n        const file = path.join(TEST_DIR, 'promise.json')\n        return fse[method](file, obj1)\n          .then(() => {\n            const data = fs.readFileSync(file, 'utf8')\n            assert.strictEqual(data, JSON.stringify(obj1) + '\\n')\n          })\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/json/__tests__/read.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('read', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'read-json')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ readJSON', () => {\n    it('should read a file and parse the json', done => {\n      const obj1 = {\n        firstName: 'JP',\n        lastName: 'Richardson'\n      }\n\n      const file = path.join(TEST_DIR, 'file.json')\n      fs.writeFileSync(file, JSON.stringify(obj1))\n      fse.readJSON(file, (err, obj2) => {\n        assert.ifError(err)\n        assert.strictEqual(obj1.firstName, obj2.firstName)\n        assert.strictEqual(obj1.lastName, obj2.lastName)\n        done()\n      })\n    })\n\n    it('should error if it cant parse the json', done => {\n      const file = path.join(TEST_DIR, 'file2.json')\n      fs.writeFileSync(file, '%asdfasdff444')\n      fse.readJSON(file, (err, obj) => {\n        assert(err)\n        assert(!obj)\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/json/index.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nconst jsonFile = require('./jsonfile')\n\njsonFile.outputJson = u(require('./output-json'))\njsonFile.outputJsonSync = require('./output-json-sync')\n// aliases\njsonFile.outputJSON = jsonFile.outputJson\njsonFile.outputJSONSync = jsonFile.outputJsonSync\njsonFile.writeJSON = jsonFile.writeJson\njsonFile.writeJSONSync = jsonFile.writeJsonSync\njsonFile.readJSON = jsonFile.readJson\njsonFile.readJSONSync = jsonFile.readJsonSync\n\nmodule.exports = jsonFile\n"
  },
  {
    "path": "lib/json/jsonfile.js",
    "content": "'use strict'\n\nconst jsonFile = require('jsonfile')\n\nmodule.exports = {\n  // jsonfile exports\n  readJson: jsonFile.readFile,\n  readJsonSync: jsonFile.readFileSync,\n  writeJson: jsonFile.writeFile,\n  writeJsonSync: jsonFile.writeFileSync\n}\n"
  },
  {
    "path": "lib/json/output-json-sync.js",
    "content": "'use strict'\n\nconst { stringify } = require('jsonfile/utils')\nconst { outputFileSync } = require('../output-file')\n\nfunction outputJsonSync (file, data, options) {\n  const str = stringify(data, options)\n\n  outputFileSync(file, str, options)\n}\n\nmodule.exports = outputJsonSync\n"
  },
  {
    "path": "lib/json/output-json.js",
    "content": "'use strict'\n\nconst { stringify } = require('jsonfile/utils')\nconst { outputFile } = require('../output-file')\n\nasync function outputJson (file, data, options = {}) {\n  const str = stringify(data, options)\n\n  await outputFile(file, str, options)\n}\n\nmodule.exports = outputJson\n"
  },
  {
    "path": "lib/mkdirs/__tests__/chmod.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('mkdirp / chmod', () => {\n  let TEST_DIR\n  let TEST_SUBDIR\n\n  beforeEach(done => {\n    const ps = []\n    for (let i = 0; i < 15; i++) {\n      const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n      ps.push(dir)\n    }\n\n    TEST_SUBDIR = ps.join(path.sep)\n\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-chmod')\n    TEST_SUBDIR = path.join(TEST_DIR, TEST_SUBDIR)\n\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('chmod-pre', done => {\n    const mode = 0o744\n    fse.mkdirp(TEST_SUBDIR, mode, err => {\n      assert.ifError(err, 'should not error')\n      fs.stat(TEST_SUBDIR, (err, stat) => {\n        assert.ifError(err, 'should exist')\n        assert.ok(stat && stat.isDirectory(), 'should be directory')\n\n        if (os.platform().indexOf('win') === 0) {\n          assert.strictEqual(stat && stat.mode & 0o777, 0o666, 'windows shit')\n        } else {\n          assert.strictEqual(stat && stat.mode & 0o777, mode, 'should be 0744')\n        }\n\n        done()\n      })\n    })\n  })\n\n  it('chmod', done => {\n    const mode = 0o755\n    fse.mkdirp(TEST_SUBDIR, mode, err => {\n      assert.ifError(err, 'should not error')\n      fs.stat(TEST_SUBDIR, (err, stat) => {\n        assert.ifError(err, 'should exist')\n        assert.ok(stat && stat.isDirectory(), 'should be directory')\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/clobber.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global before, describe, it */\n\ndescribe('mkdirp / clobber', () => {\n  let TEST_DIR\n  let file\n\n  before(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-clobber')\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n\n      const ps = [TEST_DIR]\n\n      for (let i = 0; i < 15; i++) {\n        const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n        ps.push(dir)\n      }\n\n      file = ps.join(path.sep)\n\n      // a file in the way\n      const itw = ps.slice(0, 2).join(path.sep)\n\n      fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.')\n\n      fs.stat(itw, (err, stat) => {\n        assert.ifError(err)\n        assert.ok(stat && stat.isFile(), 'should be file')\n        done()\n      })\n    })\n  })\n\n  it('should clobber', done => {\n    fse.mkdirp(file, 0o755, err => {\n      assert.ok(err)\n      assert.strictEqual(err.code, 'ENOTDIR')\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/issue-209.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst fse = require('../..')\n\n/* global describe, it */\n\ndescribe('mkdirp: issue-209, win32, when bad path, should return a cleaner error', () => {\n  // only seems to be an issue on Windows.\n  if (process.platform !== 'win32') return\n\n  it('should return a callback', done => {\n    const file = './bad?dir'\n    fse.mkdirp(file, err => {\n      assert(err, 'error is present')\n      assert.strictEqual(err.code, 'EINVAL')\n\n      const file2 = 'c:\\\\tmp\\foo:moo'\n      fse.mkdirp(file2, err => {\n        assert(err, 'error is present')\n        assert.strictEqual(err.code, 'EINVAL')\n        done()\n      })\n    })\n  })\n\n  describe('> sync', () => {\n    it('should throw an error', () => {\n      let didErr\n      try {\n        const file = 'c:\\\\tmp\\foo:moo'\n        fse.mkdirpSync(file)\n      } catch {\n        didErr = true\n      }\n      assert(didErr)\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/issue-93.test.js",
    "content": "'use strict'\n\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst util = require('util')\n\n/* global before, describe, it */\n\ndescribe('mkdirp: issue-93, win32, when drive does not exist, it should return a cleaner error', () => {\n  let TEST_DIR\n\n  // only seems to be an issue on Windows.\n  if (process.platform !== 'win32') return\n\n  before(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'tests', 'fs-extra', 'mkdirp-issue-93')\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n      done()\n    })\n  })\n\n  it('should return a cleaner error than inifinite loop, stack crash', done => {\n    const file = 'R:\\\\afasd\\\\afaff\\\\fdfd' // hopefully drive 'r' does not exist on appveyor\n    // Different error codes on different Node versions (matches native mkdir behavior)\n    const assertErr = (err) => assert(\n      ['EPERM', 'ENOENT'].includes(err.code),\n      `expected 'EPERM' or 'ENOENT', got ${util.inspect(err.code)}`\n    )\n\n    fse.mkdirp(file, err => {\n      assertErr(err)\n\n      try {\n        fse.mkdirsSync(file)\n      } catch (err) {\n        assertErr(err)\n      }\n\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/mkdir.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('fs-extra', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdir')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ mkdirs()', () => {\n    it('should make the directory', done => {\n      const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())\n\n      assert(!fs.existsSync(dir))\n\n      fse.mkdirs(dir, err => {\n        assert.ifError(err)\n        assert(fs.existsSync(dir))\n        done()\n      })\n    })\n\n    it('should make the entire directory path', done => {\n      const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())\n      const newDir = path.join(TEST_DIR, 'dfdf', 'ffff', 'aaa')\n\n      assert(!fs.existsSync(dir))\n\n      fse.mkdirs(newDir, err => {\n        assert.ifError(err)\n        assert(fs.existsSync(newDir))\n        done()\n      })\n    })\n  })\n\n  describe('+ mkdirsSync()', () => {\n    it('should make the directory', done => {\n      const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())\n\n      assert(!fs.existsSync(dir))\n      fse.mkdirsSync(dir)\n      assert(fs.existsSync(dir))\n\n      done()\n    })\n\n    it('should make the entire directory path', done => {\n      const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())\n      const newDir = path.join(dir, 'dfdf', 'ffff', 'aaa')\n\n      assert(!fs.existsSync(newDir))\n      fse.mkdirsSync(newDir)\n      assert(fs.existsSync(newDir))\n\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/mkdirp.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('mkdirp / mkdirp', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('should make the dir', done => {\n    const x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n    const y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n    const z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n\n    const file = path.join(TEST_DIR, x, y, z)\n\n    fse.mkdirp(file, 0o755, err => {\n      assert.ifError(err)\n      fse.pathExists(file, (err, ex) => {\n        assert.ifError(err)\n        assert.ok(ex, 'file created')\n        fs.stat(file, (err, stat) => {\n          assert.ifError(err)\n\n          if (os.platform().indexOf('win') === 0) {\n            assert.strictEqual(stat.mode & 0o777, 0o666)\n          } else {\n            assert.strictEqual(stat.mode & 0o777, 0o755)\n          }\n\n          assert.ok(stat.isDirectory(), 'target not a directory')\n          done()\n        })\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/opts-undef.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global beforeEach, describe, it */\n\ndescribe('mkdirs / opts-undef', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirs')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  // https://github.com/substack/node-mkdirp/issues/45\n  it('should not hang', done => {\n    const newDir = path.join(TEST_DIR, 'doest', 'not', 'exist')\n    assert(!fs.existsSync(newDir))\n\n    fse.mkdirs(newDir, undefined, err => {\n      assert.ifError(err)\n      assert(fs.existsSync(newDir))\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/perm.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('mkdirp / perm', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-perm')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('async perm', done => {\n    const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16))\n\n    fse.mkdirp(file, 0o755, err => {\n      assert.ifError(err)\n      fse.pathExists(file, (err, ex) => {\n        assert.ifError(err)\n        assert.ok(ex, 'file created')\n        fs.stat(file, (err, stat) => {\n          assert.ifError(err)\n\n          if (os.platform().indexOf('win') === 0) {\n            assert.strictEqual(stat.mode & 0o777, 0o666)\n          } else {\n            assert.strictEqual(stat.mode & 0o777, 0o755)\n          }\n\n          assert.ok(stat.isDirectory(), 'target not a directory')\n          done()\n        })\n      })\n    })\n  })\n\n  it('async root perm', done => {\n    fse.mkdirp(path.join(os.tmpdir(), 'tmp'), 0o755, err => {\n      assert.ifError(err)\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/perm_sync.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('mkdirp / perm_sync', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-perm-sync')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('sync perm', done => {\n    const file = path.join(TEST_DIR, (Math.random() * (1 << 30)).toString(16) + '.json')\n\n    fse.mkdirpSync(file, 0o755)\n    fse.pathExists(file, (err, ex) => {\n      assert.ifError(err)\n      assert.ok(ex, 'file created')\n      fs.stat(file, (err, stat) => {\n        assert.ifError(err)\n\n        if (os.platform().indexOf('win') === 0) {\n          assert.strictEqual(stat.mode & 0o777, 0o666)\n        } else {\n          assert.strictEqual(stat.mode & 0o777, 0o755)\n        }\n\n        assert.ok(stat.isDirectory(), 'target not a directory')\n        done()\n      })\n    })\n  })\n\n  it('sync root perm', done => {\n    const file = TEST_DIR\n    fse.mkdirpSync(file, 0o755)\n    fse.pathExists(file, (err, ex) => {\n      assert.ifError(err)\n      assert.ok(ex, 'file created')\n      fs.stat(file, (err, stat) => {\n        assert.ifError(err)\n        assert.ok(stat.isDirectory(), 'target not a directory')\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/race.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('mkdirp / race', () => {\n  let TEST_DIR\n  let file\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-race')\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n\n      const ps = [TEST_DIR]\n\n      for (let i = 0; i < 15; i++) {\n        const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n        ps.push(dir)\n      }\n\n      file = path.join(...ps)\n      done()\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('race', done => {\n    let res = 2\n\n    mk(file, () => --res === 0 ? done() : undefined)\n    mk(file, () => --res === 0 ? done() : undefined)\n\n    function mk (file, callback) {\n      fse.mkdirp(file, 0o755, err => {\n        assert.ifError(err)\n        fse.pathExists(file, (err, ex) => {\n          assert.ifError(err)\n          assert.ok(ex, 'file created')\n          fs.stat(file, (err, stat) => {\n            assert.ifError(err)\n\n            if (os.platform().indexOf('win') === 0) {\n              assert.strictEqual(stat.mode & 0o777, 0o666)\n            } else {\n              assert.strictEqual(stat.mode & 0o777, 0o755)\n            }\n\n            assert.ok(stat.isDirectory(), 'target not a directory')\n            if (callback) callback()\n          })\n        })\n      })\n    }\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/rel.test.js",
    "content": "'use strict'\n\nconst CWD = process.cwd()\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('mkdirp / relative', () => {\n  let TEST_DIR\n  let file\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-relative')\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n\n      const x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n      const y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n      const z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n\n      // relative path\n      file = path.join(x, y, z)\n\n      done()\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('should make the directory with relative path', done => {\n    process.chdir(TEST_DIR)\n\n    fse.mkdirp(file, 0o755, err => {\n      assert.ifError(err)\n      fse.pathExists(file, (err, ex) => {\n        assert.ifError(err)\n        assert.ok(ex, 'file created')\n        fs.stat(file, (err, stat) => {\n          assert.ifError(err)\n          // restore\n          process.chdir(CWD)\n\n          if (os.platform().indexOf('win') === 0) {\n            assert.strictEqual(stat.mode & 0o777, 0o666)\n          } else {\n            assert.strictEqual(stat.mode & 0o777, 0o755)\n          }\n\n          assert.ok(stat.isDirectory(), 'target not a directory')\n          done()\n        })\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/root.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global describe, it */\n\ndescribe('mkdirp / root', () => {\n  // '/' on unix\n  const dir = path.normalize(path.resolve(path.sep)).toLowerCase()\n\n  // Windows does not have permission to mkdir on root\n  if (process.platform === 'win32') return\n\n  it('should', done => {\n    fse.mkdirp(dir, 0o755, err => {\n      if (err) return done(err)\n      fs.stat(dir, (er, stat) => {\n        if (er) return done(er)\n        assert.ok(stat.isDirectory(), 'target is a directory')\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/__tests__/sync.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('mkdirp / sync', () => {\n  let TEST_DIR\n  let file\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-sync')\n    fse.emptyDir(TEST_DIR, err => {\n      assert.ifError(err)\n\n      const x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n      const y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n      const z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)\n\n      file = path.join(TEST_DIR, x, y, z)\n\n      done()\n    })\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  it('should', done => {\n    try {\n      fse.mkdirpSync(file, 0o755)\n    } catch (err) {\n      assert.fail(err)\n    }\n\n    fse.pathExists(file, (err, ex) => {\n      assert.ifError(err)\n      assert.ok(ex, 'file created')\n      fs.stat(file, (err, stat) => {\n        assert.ifError(err)\n        // http://stackoverflow.com/questions/592448/c-how-to-set-file-permissions-cross-platform\n        if (os.platform().indexOf('win') === 0) {\n          assert.strictEqual(stat.mode & 0o777, 0o666)\n        } else {\n          assert.strictEqual(stat.mode & 0o777, 0o755)\n        }\n\n        assert.ok(stat.isDirectory(), 'target not a directory')\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/mkdirs/index.js",
    "content": "'use strict'\nconst u = require('universalify').fromPromise\nconst { makeDir: _makeDir, makeDirSync } = require('./make-dir')\nconst makeDir = u(_makeDir)\n\nmodule.exports = {\n  mkdirs: makeDir,\n  mkdirsSync: makeDirSync,\n  // alias\n  mkdirp: makeDir,\n  mkdirpSync: makeDirSync,\n  ensureDir: makeDir,\n  ensureDirSync: makeDirSync\n}\n"
  },
  {
    "path": "lib/mkdirs/make-dir.js",
    "content": "'use strict'\nconst fs = require('../fs')\nconst { checkPath } = require('./utils')\n\nconst getMode = options => {\n  const defaults = { mode: 0o777 }\n  if (typeof options === 'number') return options\n  return ({ ...defaults, ...options }).mode\n}\n\nmodule.exports.makeDir = async (dir, options) => {\n  checkPath(dir)\n\n  return fs.mkdir(dir, {\n    mode: getMode(options),\n    recursive: true\n  })\n}\n\nmodule.exports.makeDirSync = (dir, options) => {\n  checkPath(dir)\n\n  return fs.mkdirSync(dir, {\n    mode: getMode(options),\n    recursive: true\n  })\n}\n"
  },
  {
    "path": "lib/mkdirs/utils.js",
    "content": "// Adapted from https://github.com/sindresorhus/make-dir\n// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n'use strict'\nconst path = require('path')\n\n// https://github.com/nodejs/node/issues/8987\n// https://github.com/libuv/libuv/pull/1088\nmodule.exports.checkPath = function checkPath (pth) {\n  if (process.platform === 'win32') {\n    const pathHasInvalidWinCharacters = /[<>:\"|?*]/.test(pth.replace(path.parse(pth).root, ''))\n\n    if (pathHasInvalidWinCharacters) {\n      const error = new Error(`Path contains invalid characters: ${pth}`)\n      error.code = 'EINVAL'\n      throw error\n    }\n  }\n}\n"
  },
  {
    "path": "lib/move/__tests__/cross-device-utils.js",
    "content": "const fs = require('graceful-fs')\nconst path = require('path')\n\nconst { CROSS_DEVICE_PATH } = process.env\nlet runCrossDeviceTests = !!CROSS_DEVICE_PATH\n\nif (runCrossDeviceTests) {\n  // make sure we have permission on device\n  try {\n    fs.writeFileSync(path.join(CROSS_DEVICE_PATH, 'file'), 'hi')\n  } catch {\n    runCrossDeviceTests = false\n    throw new Error(`Can't write to device ${CROSS_DEVICE_PATH}`)\n  }\n} else console.log('Skipping cross-device move tests')\n\nmodule.exports = {\n  differentDevice: CROSS_DEVICE_PATH,\n  ifCrossDeviceEnabled: (fn) => runCrossDeviceTests ? fn : fn.skip\n}\n"
  },
  {
    "path": "lib/move/__tests__/move-case-insensitive-paths.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ move() - case insensitive paths', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-case-insensitive-paths')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when src is a directory', () => {\n    it('should move successfully', done => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      dest = path.join(TEST_DIR, 'srcDir')\n\n      fs.move(src, dest, err => {\n        assert.ifError(err)\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n        done()\n      })\n    })\n  })\n\n  describe('> when src is a file', () => {\n    it('should move successfully', done => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      dest = path.join(TEST_DIR, 'srcFile')\n\n      fs.move(src, dest, err => {\n        assert.ifError(err)\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n        done()\n      })\n    })\n  })\n\n  describe('> when src is a symlink', () => {\n    it('should move successfully, symlink dir', done => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'dir')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n\n      fs.move(srcLink, dest, err => {\n        assert.ifError(err)\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n        const destLink = fs.readlinkSync(dest)\n        assert.strictEqual(destLink, src)\n        done()\n      })\n    })\n\n    it('should move successfully, symlink file', done => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'file')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n\n      fs.move(srcLink, dest, err => {\n        assert.ifError(err)\n        assert(fs.existsSync(dest))\n        assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n        const destLink = fs.readlinkSync(dest)\n        assert.strictEqual(destLink, src)\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/move/__tests__/move-preserve-timestamp.test.js",
    "content": "'use strict'\n\nconst fs = require('../../')\nconst os = require('os')\nconst path = require('path')\nconst utimesSync = require('../../util/utimes').utimesMillisSync\nconst assert = require('assert')\nconst fse = require('../../index')\nconst { differentDevice, ifCrossDeviceEnabled } = require('./cross-device-utils')\n\n/* global beforeEach, afterEach, describe, it */\n\nif (process.arch === 'ia32') console.warn('32 bit arch; skipping move timestamp tests')\n\nconst describeIfPractical = process.arch === 'ia32' ? describe.skip : describe\n\ndescribeIfPractical('move() - across different devices', () => {\n  let TEST_DIR, SRC, DEST, FILES\n\n  function setupFixture (readonly) {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-sync-preserve-timestamp')\n    SRC = path.join(differentDevice, 'some/weird/dir-really-weird')\n    DEST = path.join(TEST_DIR, 'dest')\n    FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')]\n    const timestamp = Date.now() / 1000 - 5\n    FILES.forEach(f => {\n      const filePath = path.join(SRC, f)\n      fs.ensureFileSync(filePath)\n      // rewind timestamps to make sure that coarser OS timestamp resolution\n      // does not alter results\n      utimesSync(filePath, timestamp, timestamp)\n      if (readonly) {\n        fs.chmodSync(filePath, 0o444)\n      }\n    })\n  }\n\n  afterEach(() => {\n    fse.removeSync(TEST_DIR)\n    fse.removeSync(SRC)\n  })\n\n  ifCrossDeviceEnabled(describe)('> default behaviour', () => {\n    ;[\n      { subcase: 'writable', readonly: false },\n      { subcase: 'readonly', readonly: true }\n    ].forEach(params => {\n      describe(`>> with ${params.subcase} source files`, () => {\n        beforeEach(() => setupFixture(params.readonly))\n\n        it('should have the same timestamps after move', done => {\n          const originalTimestamps = FILES.map(file => {\n            const originalPath = path.join(SRC, file)\n            const originalStat = fs.statSync(originalPath)\n            return {\n              mtime: originalStat.mtime.getTime(),\n              atime: originalStat.atime.getTime()\n            }\n          })\n          fse.move(SRC, DEST, {}, (err) => {\n            if (err) return done(err)\n            FILES.forEach(testFile({}, originalTimestamps))\n            done()\n          })\n        })\n      })\n    })\n  })\n\n  function testFile (options, originalTimestamps) {\n    return function (file, idx) {\n      const originalTimestamp = originalTimestamps[idx]\n      const currentPath = path.join(DEST, file)\n      const currentStats = fs.statSync(currentPath)\n      assert.strictEqual(currentStats.mtime.getTime(), originalTimestamp.mtime, 'different mtime values')\n      assert.strictEqual(currentStats.atime.getTime(), originalTimestamp.atime, 'different atime values')\n    }\n  }\n})\n"
  },
  {
    "path": "lib/move/__tests__/move-prevent-moving-identical.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ move() - prevent moving identical files and dirs', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-prevent-moving-identical')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  it('should return an error if src and dest are the same', done => {\n    const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_move')\n    const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_move')\n    fs.ensureFileSync(fileSrc)\n\n    fs.move(fileSrc, fileDest, err => {\n      assert.strictEqual(err.message, 'Source and destination must not be the same.')\n      done()\n    })\n  })\n\n  describe('dest with parent symlink', () => {\n    describe('first parent is symlink', () => {\n      it('should error when src is file', done => {\n        const src = path.join(TEST_DIR, 'a', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.move(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n\n      it('should error when src is directory', done => {\n        const src = path.join(TEST_DIR, 'a', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.move(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n    })\n\n    describe('nested dest', () => {\n      it('should error when src is file', done => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.move(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n\n      it('should error when src is directory', done => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        fs.move(src, dest, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          assert(fs.existsSync(src))\n          done()\n        })\n      })\n    })\n  })\n\n  // src is directory:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a directory', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error if dereference is true', done => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const subdir = path.join(TEST_DIR, 'src', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const oldlen = klawSync(src).length\n\n        fs.move(src, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const newlen = klawSync(src).length\n          assert.strictEqual(newlen, oldlen)\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error', done => {\n        dest = path.join(TEST_DIR, 'dest')\n        fs.mkdirsSync(dest)\n        const subdir = path.join(TEST_DIR, 'dest', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'dir')\n\n        const oldlen = klawSync(dest).length\n\n        fs.move(srcLink, dest, err => {\n          assert.ok(err)\n\n          // assert nothing copied\n          const newlen = klawSync(dest).length\n          assert.strictEqual(newlen, oldlen)\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, dest)\n          done()\n        })\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error src and dest are the same and dereference is true', done => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n\n        fs.move(srcLink, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const srclenAfter = klawSync(srcLink).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const destlenAfter = klawSync(destLink).length\n          assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n          done()\n        })\n      })\n    })\n  })\n\n  // src is file:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a file', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error if dereference is true', done => {\n        src = path.join(TEST_DIR, 'src.txt')\n        fs.outputFileSync(src, 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        fs.move(src, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          done()\n        })\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error if dereferene is true', done => {\n        dest = path.join(TEST_DIR, 'dest', 'somefile.txt')\n        fs.outputFileSync(dest, 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'file')\n\n        fs.move(srcLink, dest, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, dest)\n          assert(fs.readFileSync(link, 'utf8'), 'some data')\n          done()\n        })\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error src and dest are the same and dereferene is true', done => {\n        src = path.join(TEST_DIR, 'src', 'srcfile.txt')\n        fs.outputFileSync(src, 'src data')\n\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'file')\n\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        fs.move(srcLink, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n          assert(fs.readFileSync(srcln, 'utf8'), 'src data')\n          assert(fs.readFileSync(destln, 'utf8'), 'src data')\n          done()\n        })\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/move/__tests__/move-prevent-moving-into-itself.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\n// these files are used for all tests\nconst FILES = [\n  'file0.txt',\n  path.join('dir1', 'file1.txt'),\n  path.join('dir1', 'dir2', 'file2.txt'),\n  path.join('dir1', 'dir2', 'dir3', 'file3.txt')\n]\n\nconst dat0 = 'file0'\nconst dat1 = 'file1'\nconst dat2 = 'file2'\nconst dat3 = 'file3'\n\ndescribe('+ move() - prevent moving into itself', () => {\n  let TEST_DIR, src\n\n  beforeEach(() => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-prevent-moving-into-itself')\n    src = path.join(TEST_DIR, 'src')\n    fs.mkdirpSync(src)\n\n    fs.outputFileSync(path.join(src, FILES[0]), dat0)\n    fs.outputFileSync(path.join(src, FILES[1]), dat1)\n    fs.outputFileSync(path.join(src, FILES[2]), dat2)\n    fs.outputFileSync(path.join(src, FILES[3]), dat3)\n  })\n\n  afterEach(() => fs.removeSync(TEST_DIR))\n\n  describe('> when source is a file', () => {\n    it('should move the file successfully even if dest parent is a subdir of src', done => {\n      const srcFile = path.join(TEST_DIR, 'src', 'srcfile.txt')\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'destfile.txt')\n      fs.writeFileSync(srcFile, dat0)\n\n      fs.move(srcFile, destFile, err => {\n        assert.ifError(err)\n\n        assert(fs.existsSync(destFile))\n        const out = fs.readFileSync(destFile, 'utf8')\n        assert.strictEqual(out, dat0, 'file contents matched')\n        done()\n      })\n    })\n    it(\"should move the file successfully even when dest parent is 'src/dest'\", done => {\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'destfile.txt')\n      return testSuccessFile(src, destFile, done)\n    })\n\n    it(\"should move the file successfully when dest parent is 'src/src_dest'\", done => {\n      const destFile = path.join(TEST_DIR, 'src', 'src_dest', 'destfile.txt')\n      return testSuccessFile(src, destFile, done)\n    })\n\n    it(\"should move the file successfully when dest parent is 'src/dest_src'\", done => {\n      const destFile = path.join(TEST_DIR, 'src', 'dest_src', 'destfile.txt')\n      return testSuccessFile(src, destFile, done)\n    })\n\n    it(\"should move the file successfully when dest parent is 'src/dest/src'\", done => {\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'src', 'destfile.txt')\n      return testSuccessFile(src, destFile, done)\n    })\n\n    it(\"should move the file successfully when dest parent is 'srcsrc/dest'\", done => {\n      const destFile = path.join(TEST_DIR, 'srcsrc', 'dest', 'destfile.txt')\n      return testSuccessFile(src, destFile, done)\n    })\n  })\n\n  describe('> when source is a directory', () => {\n    describe('>> when dest is a directory', () => {\n      it('of not itself', done => {\n        const dest = path.join(TEST_DIR, src.replace(/^\\w:/, ''))\n        return testSuccessDir(src, dest, done)\n      })\n      it('of itself', done => {\n        const dest = path.join(src, 'dest')\n        return testError(src, dest, done)\n      })\n      it(\"should move the directory successfully when dest is 'src_dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src_dest')\n        return testSuccessDir(src, dest, done)\n      })\n      it(\"should move the directory successfully when dest is 'src-dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src-dest')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'dest_src'\", done => {\n        const dest = path.join(TEST_DIR, 'dest_src')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'src_dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'src_dest', 'src')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'src-dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'src-dest', 'src')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'dest_src/src'\", done => {\n        const dest = path.join(TEST_DIR, 'dest_src', 'src')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'src_src/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'src-src/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src-src', 'dest')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'srcsrc/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should move the directory successfully when dest is 'dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'dest', 'src')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it('should move the directory successfully when dest is very nested that all its parents need to be created', done => {\n        const dest = path.join(TEST_DIR, 'dest', 'src', 'foo', 'bar', 'baz', 'qux', 'quux', 'waldo',\n          'grault', 'garply', 'fred', 'plugh', 'thud', 'some', 'highly', 'deeply',\n          'badly', 'nasty', 'crazy', 'mad', 'nested', 'dest')\n        return testSuccessDir(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'dest')\n        return testError(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/src_dest'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'src_dest')\n        return testError(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/dest_src'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'dest_src')\n        return testError(src, dest, done)\n      })\n\n      it(\"should error when dest is 'src/dest/src'\", done => {\n        const dest = path.join(TEST_DIR, 'src', 'dest', 'src')\n        return testError(src, dest, done)\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when dest is a subdirectory of src (bind-mounted directory with subdirectory)', done => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1')\n        assert(fs.existsSync(dest))\n        fs.move(src, dest, err => {\n          assert.strictEqual(err.message, `Cannot move '${src}' to a subdirectory of itself, '${dest}'.`)\n\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should error when dest is a subdirectory of src (more than one level depth)', done => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1', 'dir2')\n        assert(fs.existsSync(dest))\n        fs.move(src, dest, err => {\n          assert.strictEqual(err.message, `Cannot move '${src}' to a subdirectory of itself, '${path.join(destLink, 'dir1')}'.`)\n\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n    })\n  })\n\n  describe('> when source is a symlink', () => {\n    describe('>> when dest is a directory', () => {\n      it('should error when resolved src path points to dest', done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src')\n\n        fs.move(srcLink, dest, err => {\n          assert(err)\n          // assert source not affected\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should error when dest is a subdir of resolved src path', done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src', 'some', 'nested', 'dest')\n        fs.mkdirsSync(dest)\n\n        fs.move(srcLink, dest, err => {\n          assert(err)\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it('should error when resolved src path is a subdir of dest', done => {\n        const dest = path.join(TEST_DIR, 'dest')\n\n        const resolvedSrcPath = path.join(dest, 'contains', 'src')\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.copySync(src, resolvedSrcPath)\n\n        // make symlink that points to a subdir in dest\n        fs.symlinkSync(resolvedSrcPath, srcLink, 'dir')\n\n        fs.move(srcLink, dest, err => {\n          assert(err)\n          done()\n        })\n      })\n\n      it(\"should move the directory successfully when dest is 'src_src/dest'\", done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        testSuccessDir(srcLink, dest, () => {\n          const link = fs.readlinkSync(dest)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n\n      it(\"should move the directory successfully when dest is 'srcsrc/dest'\", done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        testSuccessDir(srcLink, dest, () => {\n          const link = fs.readlinkSync(dest)\n          assert.strictEqual(link, src)\n          done()\n        })\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when resolved dest path is exactly the same as resolved src path and dereferene is true', done => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n        assert(srclenBefore > 2)\n        assert(destlenBefore > 2)\n\n        fs.move(srcLink, destLink, { dereference: true }, err => {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n\n          const srclenAfter = klawSync(srcLink).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const destlenAfter = klawSync(destLink).length\n          assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n          done()\n        })\n      })\n    })\n  })\n})\n\nfunction testSuccessFile (src, destFile, done) {\n  const srcFile = path.join(src, FILES[0])\n\n  fs.move(srcFile, destFile, err => {\n    assert.ifError(err)\n    const f0 = fs.readFileSync(destFile, 'utf8')\n    assert.strictEqual(f0, dat0, 'file contents matched')\n    assert(!fs.existsSync(srcFile))\n    return done()\n  })\n}\n\nfunction testSuccessDir (src, dest, done) {\n  const srclen = klawSync(src).length\n\n  assert(srclen > 2) // assert src has contents\n\n  fs.move(src, dest, err => {\n    assert.ifError(err)\n    const destlen = klawSync(dest).length\n\n    assert.strictEqual(destlen, srclen, 'src and dest length should be equal')\n\n    const f0 = fs.readFileSync(path.join(dest, FILES[0]), 'utf8')\n    const f1 = fs.readFileSync(path.join(dest, FILES[1]), 'utf8')\n    const f2 = fs.readFileSync(path.join(dest, FILES[2]), 'utf8')\n    const f3 = fs.readFileSync(path.join(dest, FILES[3]), 'utf8')\n\n    assert.strictEqual(f0, dat0, 'file contents matched')\n    assert.strictEqual(f1, dat1, 'file contents matched')\n    assert.strictEqual(f2, dat2, 'file contents matched')\n    assert.strictEqual(f3, dat3, 'file contents matched')\n    assert(!fs.existsSync(src))\n    return done()\n  })\n}\n\nfunction testError (src, dest, done) {\n  fs.move(src, dest, err => {\n    assert(err)\n    assert.strictEqual(err.message, `Cannot move '${src}' to a subdirectory of itself, '${dest}'.`)\n    assert(fs.existsSync(src))\n    assert(!fs.existsSync(dest))\n    return done()\n  })\n}\n"
  },
  {
    "path": "lib/move/__tests__/move-sync-case-insensitive-paths.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ moveSync() - case insensitive paths', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-sync-case-insensitive-paths')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(() => fs.removeSync(TEST_DIR))\n\n  describe('> when src is a directory', () => {\n    it('should move successfully', () => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      dest = path.join(TEST_DIR, 'srcDir')\n\n      fs.moveSync(src, dest)\n      assert(fs.existsSync(dest))\n      assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n    })\n  })\n\n  describe('> when src is a file', () => {\n    it('should move successfully', () => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      dest = path.join(TEST_DIR, 'srcFile')\n\n      fs.moveSync(src, dest)\n      assert(fs.existsSync(dest))\n      assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n    })\n  })\n\n  describe('> when src is a symlink', () => {\n    it('should move successfully, symlink dir', () => {\n      src = path.join(TEST_DIR, 'srcdir')\n      fs.outputFileSync(path.join(src, 'subdir', 'file.txt'), 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'dir')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n\n      fs.moveSync(srcLink, dest)\n      assert(fs.existsSync(dest))\n      assert.strictEqual(fs.readFileSync(path.join(dest, 'subdir', 'file.txt'), 'utf8'), 'some data')\n      const destLink = fs.readlinkSync(dest)\n      assert.strictEqual(destLink, src)\n    })\n\n    it('should move successfully, symlink file', () => {\n      src = path.join(TEST_DIR, 'srcfile')\n      fs.outputFileSync(src, 'some data')\n      const srcLink = path.join(TEST_DIR, 'src-symlink')\n      fs.symlinkSync(src, srcLink, 'file')\n      dest = path.join(TEST_DIR, 'src-Symlink')\n\n      fs.moveSync(srcLink, dest)\n      assert(fs.existsSync(dest))\n      assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'some data')\n      const destLink = fs.readlinkSync(dest)\n      assert.strictEqual(destLink, src)\n    })\n  })\n})\n"
  },
  {
    "path": "lib/move/__tests__/move-sync-preserve-timestamp.test.js",
    "content": "'use strict'\n\nconst fs = require('../../')\nconst os = require('os')\nconst path = require('path')\nconst utimesSync = require('../../util/utimes').utimesMillisSync\nconst assert = require('assert')\nconst fse = require('../../index')\nconst { differentDevice, ifCrossDeviceEnabled } = require('./cross-device-utils')\n\n/* global beforeEach, afterEach, describe, it */\n\nif (process.arch === 'ia32') console.warn('32 bit arch; skipping move timestamp tests')\n\nconst describeIfPractical = process.arch === 'ia32' ? describe.skip : describe\n\ndescribeIfPractical('moveSync() - across different devices', () => {\n  let TEST_DIR, SRC, DEST, FILES\n\n  function setupFixture (readonly) {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-sync-preserve-timestamp')\n    SRC = path.join(differentDevice, 'some/weird/dir-really-weird')\n    DEST = path.join(TEST_DIR, 'dest')\n    FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')]\n    const timestamp = Date.now() / 1000 - 5\n    FILES.forEach(f => {\n      const filePath = path.join(SRC, f)\n      fs.ensureFileSync(filePath)\n      // rewind timestamps to make sure that coarser OS timestamp resolution\n      // does not alter results\n      utimesSync(filePath, timestamp, timestamp)\n      if (readonly) {\n        fs.chmodSync(filePath, 0o444)\n      }\n    })\n  }\n\n  afterEach(() => {\n    fse.removeSync(TEST_DIR)\n    fse.removeSync(SRC)\n  })\n\n  ifCrossDeviceEnabled(describe)('> default behaviour', () => {\n    ;[\n      { subcase: 'writable', readonly: false },\n      { subcase: 'readonly', readonly: true }\n    ].forEach(params => {\n      describe(`>> with ${params.subcase} source files`, () => {\n        beforeEach(() => setupFixture(params.readonly))\n\n        it('should have the same timestamps after move', () => {\n          const originalTimestamps = FILES.map(file => {\n            const originalPath = path.join(SRC, file)\n            const originalStat = fs.statSync(originalPath)\n            return {\n              mtime: originalStat.mtime.getTime(),\n              atime: originalStat.atime.getTime()\n            }\n          })\n          fse.moveSync(SRC, DEST, {})\n          FILES.forEach(testFile({}, originalTimestamps))\n        })\n      })\n    })\n  })\n\n  function testFile (options, originalTimestamps) {\n    return function (file, idx) {\n      const originalTimestamp = originalTimestamps[idx]\n      const currentPath = path.join(DEST, file)\n      const currentStats = fs.statSync(currentPath)\n      // Windows sub-second precision fixed: https://github.com/nodejs/io.js/issues/2069\n      assert.strictEqual(currentStats.mtime.getTime(), originalTimestamp.mtime, 'different mtime values')\n      assert.strictEqual(currentStats.atime.getTime(), originalTimestamp.atime, 'different atime values')\n    }\n  }\n})\n"
  },
  {
    "path": "lib/move/__tests__/move-sync-prevent-moving-identical.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('+ moveSync() - prevent moving identical files and dirs', () => {\n  let TEST_DIR = ''\n  let src = ''\n  let dest = ''\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-sync-prevent-moving-identical')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  it('should return an error if src and dest are the same', () => {\n    const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_move_sync')\n    const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_move_sync')\n    fs.ensureFileSync(fileSrc)\n\n    try {\n      fs.moveSync(fileSrc, fileDest)\n    } catch (err) {\n      assert.strictEqual(err.message, 'Source and destination must not be the same.')\n    }\n  })\n\n  describe('dest with parent symlink', () => {\n    describe('first parent is symlink', () => {\n      it('should error when src is file', () => {\n        const src = path.join(TEST_DIR, 'a', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.moveSync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n\n      it('should error when src is directory', () => {\n        const src = path.join(TEST_DIR, 'a', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.moveSync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n    })\n\n    describe('nested dest', () => {\n      it('should error when src is file', () => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'file.txt')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'file.txt')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureFileSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.moveSync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n\n      it('should error when src is directory', () => {\n        const src = path.join(TEST_DIR, 'a', 'dir', 'foo')\n        const dest = path.join(TEST_DIR, 'b', 'dir', 'foo')\n        const srcParent = path.join(TEST_DIR, 'a')\n        const destParent = path.join(TEST_DIR, 'b')\n        fs.ensureDirSync(src)\n        fs.ensureSymlinkSync(srcParent, destParent, 'dir')\n\n        try {\n          fs.moveSync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        } finally {\n          assert(fs.existsSync(src))\n        }\n      })\n    })\n  })\n\n  // src is directory:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a directory', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error if dereferene is true', () => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const subdir = path.join(TEST_DIR, 'src', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const oldlen = klawSync(src).length\n\n        try {\n          fs.moveSync(src, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const newlen = klawSync(src).length\n        assert.strictEqual(newlen, oldlen)\n        const link = fs.readlinkSync(destLink)\n        assert.strictEqual(link, src)\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error', () => {\n        dest = path.join(TEST_DIR, 'dest')\n        fs.mkdirsSync(dest)\n        const subdir = path.join(TEST_DIR, 'dest', 'subdir')\n        fs.mkdirsSync(subdir)\n        fs.writeFileSync(path.join(subdir, 'file.txt'), 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'dir')\n\n        const oldlen = klawSync(dest).length\n\n        try {\n          fs.moveSync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n        }\n\n        // assert nothing copied\n        const newlen = klawSync(dest).length\n        assert.strictEqual(newlen, oldlen)\n        const link = fs.readlinkSync(srcLink)\n        assert.strictEqual(link, dest)\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error if src and dest are the same and dereference is true', () => {\n        src = path.join(TEST_DIR, 'src')\n        fs.mkdirsSync(src)\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n\n        try {\n          fs.moveSync(srcLink, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const srclenAfter = klawSync(srcLink).length\n        assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n        const destlenAfter = klawSync(destLink).length\n        assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n        const srcln = fs.readlinkSync(srcLink)\n        assert.strictEqual(srcln, src)\n        const destln = fs.readlinkSync(destLink)\n        assert.strictEqual(destln, src)\n      })\n    })\n  })\n\n  // src is file:\n  //  src is regular, dest is symlink\n  //  src is symlink, dest is regular\n  //  src is symlink, dest is symlink\n\n  describe('> when src is a file', () => {\n    describe('>> when src is regular and dest is a symlink that points to src', () => {\n      it('should error if dereference is true', () => {\n        src = path.join(TEST_DIR, 'src', 'somefile.txt')\n        fs.ensureFileSync(src)\n        fs.writeFileSync(src, 'some data')\n\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        try {\n          fs.moveSync(src, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const link = fs.readlinkSync(destLink)\n        assert.strictEqual(link, src)\n        assert(fs.readFileSync(link, 'utf8'), 'some data')\n      })\n    })\n\n    describe('>> when src is a symlink that points to a regular dest', () => {\n      it('should throw error', () => {\n        dest = path.join(TEST_DIR, 'dest', 'somefile.txt')\n        fs.outputFileSync(dest, 'some data')\n\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(dest, srcLink, 'file')\n\n        try {\n          fs.moveSync(srcLink, dest)\n        } catch (err) {\n          assert.ok(err)\n        }\n        const link = fs.readlinkSync(srcLink)\n        assert.strictEqual(link, dest)\n        assert(fs.readFileSync(link, 'utf8'), 'some data')\n      })\n    })\n\n    describe('>> when src and dest are symlinks that point to the exact same path', () => {\n      it('should error if src and dest are the same and dereference is true', () => {\n        src = path.join(TEST_DIR, 'src', 'srcfile.txt')\n        fs.outputFileSync(src, 'src data')\n\n        const srcLink = path.join(TEST_DIR, 'src_symlink')\n        fs.symlinkSync(src, srcLink, 'file')\n\n        const destLink = path.join(TEST_DIR, 'dest_symlink')\n        fs.symlinkSync(src, destLink, 'file')\n\n        try {\n          fs.moveSync(srcLink, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        }\n\n        const srcln = fs.readlinkSync(srcLink)\n        assert.strictEqual(srcln, src)\n        const destln = fs.readlinkSync(destLink)\n        assert.strictEqual(destln, src)\n        assert(fs.readFileSync(srcln, 'utf8'), 'src data')\n        assert(fs.readFileSync(destln, 'utf8'), 'src data')\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/move/__tests__/move-sync-prevent-moving-into-itself.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst os = require('os')\nconst path = require('path')\nconst fs = require('../../')\nconst klawSync = require('klaw-sync')\n\n/* global beforeEach, afterEach, describe, it */\n\n// these files are used for all tests\nconst FILES = [\n  'file0.txt',\n  path.join('dir1', 'file1.txt'),\n  path.join('dir1', 'dir2', 'file2.txt'),\n  path.join('dir1', 'dir2', 'dir3', 'file3.txt')\n]\n\nconst dat0 = 'file0'\nconst dat1 = 'file1'\nconst dat2 = 'file2'\nconst dat3 = 'file3'\n\ndescribe('+ moveSync() - prevent moving into itself', () => {\n  let TEST_DIR, src\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-sync-prevent-moving-into-itself')\n    src = path.join(TEST_DIR, 'src')\n    fs.mkdirpSync(src)\n\n    fs.outputFileSync(path.join(src, FILES[0]), dat0)\n    fs.outputFileSync(path.join(src, FILES[1]), dat1)\n    fs.outputFileSync(path.join(src, FILES[2]), dat2)\n    fs.outputFileSync(path.join(src, FILES[3]), dat3)\n    done()\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('> when source is a file', () => {\n    it('should move the file successfully even if dest parent is a subdir of src', () => {\n      const srcFile = path.join(TEST_DIR, 'src', 'srcfile.txt')\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'destfile.txt')\n      fs.writeFileSync(srcFile, dat0)\n\n      fs.moveSync(srcFile, destFile)\n\n      assert(fs.existsSync(destFile))\n      const out = fs.readFileSync(destFile, 'utf8')\n      assert.strictEqual(out, dat0, 'file contents matched')\n    })\n  })\n\n  describe('> when source is a file', () => {\n    it(\"should move the file successfully even when dest parent is 'src/dest'\", () => {\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'destfile.txt')\n      return testSuccessFile(src, destFile)\n    })\n\n    it(\"should move the file successfully when dest parent is 'src/src_dest'\", () => {\n      const destFile = path.join(TEST_DIR, 'src', 'src_dest', 'destfile.txt')\n      return testSuccessFile(src, destFile)\n    })\n\n    it(\"should move the file successfully when dest parent is 'src/dest_src'\", () => {\n      const destFile = path.join(TEST_DIR, 'src', 'dest_src', 'destfile.txt')\n      return testSuccessFile(src, destFile)\n    })\n\n    it(\"should move the file successfully when dest parent is 'src/dest/src'\", () => {\n      const destFile = path.join(TEST_DIR, 'src', 'dest', 'src', 'destfile.txt')\n      return testSuccessFile(src, destFile)\n    })\n\n    it(\"should move the file successfully when dest parent is 'srcsrc/dest'\", () => {\n      const destFile = path.join(TEST_DIR, 'srcsrc', 'dest', 'destfile.txt')\n      return testSuccessFile(src, destFile)\n    })\n  })\n\n  describe('> when source is a directory', () => {\n    describe('>> when dest is a directory', () => {\n      it('of not itself', () => {\n        const dest = path.join(TEST_DIR, src.replace(/^\\w:/, ''))\n        return testSuccessDir(src, dest)\n      })\n      it('of itself', () => {\n        const dest = path.join(src, 'dest')\n        return testError(src, dest)\n      })\n      it(\"should move the directory successfully when dest is 'src_dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src_dest')\n        return testSuccessDir(src, dest)\n      })\n      it(\"should move the directory successfully when dest is 'src-dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src-dest')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'dest_src'\", () => {\n        const dest = path.join(TEST_DIR, 'dest_src')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'src_dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'src_dest', 'src')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'src-dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'src-dest', 'src')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'dest_src/src'\", () => {\n        const dest = path.join(TEST_DIR, 'dest_src', 'src')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'src_src/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'src-src/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src-src', 'dest')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'srcsrc/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should move the directory successfully when dest is 'dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'dest', 'src')\n        return testSuccessDir(src, dest)\n      })\n\n      it('should move the directory successfully when dest is very nested that all its parents need to be created', () => {\n        const dest = path.join(TEST_DIR, 'dest', 'src', 'foo', 'bar', 'baz', 'qux', 'quux', 'waldo',\n          'grault', 'garply', 'fred', 'plugh', 'thud', 'some', 'highly', 'deeply',\n          'badly', 'nasty', 'crazy', 'mad', 'nested', 'dest')\n        return testSuccessDir(src, dest)\n      })\n\n      it(\"should error when dest is 'src/dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'dest')\n        return testError(src, dest)\n      })\n\n      it(\"should error when dest is 'src/src_dest'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'src_dest')\n        return testError(src, dest)\n      })\n\n      it(\"should error when dest is 'src/dest_src'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'dest_src')\n        return testError(src, dest)\n      })\n\n      it(\"should error when dest is 'src/dest/src'\", () => {\n        const dest = path.join(TEST_DIR, 'src', 'dest', 'src')\n        return testError(src, dest)\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when dest points exactly to src and dereference is true', () => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n        let errThrown = false\n        try {\n          fs.moveSync(src, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n        }\n      })\n\n      it('should error when dest is a subdirectory of src (bind-mounted directory with subdirectory)', () => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1')\n        assert(fs.existsSync(dest))\n        let errThrown = false\n        try {\n          fs.moveSync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot move '${src}' to a subdirectory of itself, '${dest}'.`)\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n        }\n      })\n\n      it('should error when dest is a subdirectory of src (more than one level depth)', () => {\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(src).length\n        assert(srclenBefore > 2)\n\n        const dest = path.join(destLink, 'dir1', 'dir2')\n        assert(fs.existsSync(dest))\n        let errThrown = false\n        try {\n          fs.moveSync(src, dest)\n        } catch (err) {\n          assert.strictEqual(err.message, `Cannot move '${src}' to a subdirectory of itself, '${path.join(destLink, 'dir1')}'.`)\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          const srclenAfter = klawSync(src).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const link = fs.readlinkSync(destLink)\n          assert.strictEqual(link, src)\n        }\n      })\n    })\n  })\n\n  describe('> when source is a symlink', () => {\n    describe('>> when dest is a directory', () => {\n      it('should error when resolved src path points to dest', () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src')\n        let errThrown = false\n        try {\n          fs.moveSync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          // assert source not affected\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, src)\n        }\n      })\n\n      it('should error when dest is a subdir of resolved src path', () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src', 'some', 'nested', 'dest')\n        fs.mkdirsSync(dest)\n        let errThrown = false\n        try {\n          fs.moveSync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          const link = fs.readlinkSync(srcLink)\n          assert.strictEqual(link, src)\n        }\n      })\n\n      it('should error when resolved src path is a subdir of dest', () => {\n        const dest = path.join(TEST_DIR, 'dest')\n\n        const resolvedSrcPath = path.join(dest, 'contains', 'src')\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.copySync(src, resolvedSrcPath)\n\n        // make symlink that points to a subdir in dest\n        fs.symlinkSync(resolvedSrcPath, srcLink, 'dir')\n\n        let errThrown = false\n        try {\n          fs.moveSync(srcLink, dest)\n        } catch (err) {\n          assert(err)\n          errThrown = true\n        } finally {\n          assert(errThrown)\n        }\n      })\n\n      it(\"should move the directory successfully when dest is 'src_src/dest'\", () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'src_src', 'dest')\n        testSuccessDir(srcLink, dest)\n        const link = fs.readlinkSync(dest)\n        assert.strictEqual(link, src)\n      })\n\n      it(\"should move the directory successfully when dest is 'srcsrc/dest'\", () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n\n        const dest = path.join(TEST_DIR, 'srcsrc', 'dest')\n        testSuccessDir(srcLink, dest)\n        const link = fs.readlinkSync(dest)\n        assert.strictEqual(link, src)\n      })\n    })\n\n    describe('>> when dest is a symlink', () => {\n      it('should error when resolved dest path is exactly the same as resolved src path and dereferene is true', () => {\n        const srcLink = path.join(TEST_DIR, 'src-symlink')\n        fs.symlinkSync(src, srcLink, 'dir')\n        const destLink = path.join(TEST_DIR, 'dest-symlink')\n        fs.symlinkSync(src, destLink, 'dir')\n\n        const srclenBefore = klawSync(srcLink).length\n        const destlenBefore = klawSync(destLink).length\n        assert(srclenBefore > 2)\n        assert(destlenBefore > 2)\n        let errThrown = false\n        try {\n          fs.moveSync(srcLink, destLink, { dereference: true })\n        } catch (err) {\n          assert.strictEqual(err.message, 'Source and destination must not be the same.')\n          errThrown = true\n        } finally {\n          assert(errThrown)\n          const srclenAfter = klawSync(srcLink).length\n          assert.strictEqual(srclenAfter, srclenBefore, 'src length should not change')\n          const destlenAfter = klawSync(destLink).length\n          assert.strictEqual(destlenAfter, destlenBefore, 'dest length should not change')\n\n          const srcln = fs.readlinkSync(srcLink)\n          assert.strictEqual(srcln, src)\n          const destln = fs.readlinkSync(destLink)\n          assert.strictEqual(destln, src)\n        }\n      })\n    })\n  })\n})\n\nfunction testSuccessFile (src, destFile) {\n  const srcFile = path.join(src, FILES[0])\n\n  fs.moveSync(srcFile, destFile)\n  const f0 = fs.readFileSync(destFile, 'utf8')\n  assert.strictEqual(f0, dat0, 'file contents matched')\n  assert(!fs.existsSync(srcFile))\n}\n\nfunction testSuccessDir (src, dest) {\n  const srclen = klawSync(src).length\n\n  assert(srclen > 2) // assert src has contents\n\n  fs.moveSync(src, dest)\n  const destlen = klawSync(dest).length\n\n  assert.strictEqual(destlen, srclen, 'src and dest length should be equal')\n\n  const f0 = fs.readFileSync(path.join(dest, FILES[0]), 'utf8')\n  const f1 = fs.readFileSync(path.join(dest, FILES[1]), 'utf8')\n  const f2 = fs.readFileSync(path.join(dest, FILES[2]), 'utf8')\n  const f3 = fs.readFileSync(path.join(dest, FILES[3]), 'utf8')\n\n  assert.strictEqual(f0, dat0, 'file contents matched')\n  assert.strictEqual(f1, dat1, 'file contents matched')\n  assert.strictEqual(f2, dat2, 'file contents matched')\n  assert.strictEqual(f3, dat3, 'file contents matched')\n  assert(!fs.existsSync(src))\n}\n\nfunction testError (src, dest) {\n  let errThrown = false\n  try {\n    fs.moveSync(src, dest)\n  } catch (err) {\n    assert.strictEqual(err.message, `Cannot move '${src}' to a subdirectory of itself, '${dest}'.`)\n    assert(fs.existsSync(src))\n    assert(!fs.existsSync(dest))\n    errThrown = true\n  } finally {\n    assert(errThrown)\n  }\n}\n"
  },
  {
    "path": "lib/move/__tests__/move-sync.test.js",
    "content": "'use strict'\n\n// TODO: enable this once graceful-fs supports bigint option.\n// const fs = require('graceful-fs')\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst { differentDevice, ifCrossDeviceEnabled } = require('./cross-device-utils')\n\n/* global afterEach, beforeEach, describe, it */\n\nconst describeIfWindows = process.platform === 'win32' ? describe : describe.skip\n\nfunction createSyncErrFn (errCode) {\n  const fn = function () {\n    const err = new Error()\n    err.code = errCode\n    throw err\n  }\n  return fn\n}\n\nconst originalRenameSync = fs.renameSync\n\nfunction setUpMockFs (errCode) {\n  fs.renameSync = createSyncErrFn(errCode)\n}\n\nfunction tearDownMockFs () {\n  fs.renameSync = originalRenameSync\n}\n\ndescribe('moveSync()', () => {\n  let TEST_DIR\n\n  beforeEach(() => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move-sync')\n    fse.emptyDirSync(TEST_DIR)\n\n    // Create fixtures\n    fse.outputFileSync(path.join(TEST_DIR, 'a-file'), 'sonic the hedgehog\\n')\n    fse.outputFileSync(path.join(TEST_DIR, 'a-folder/another-file'), 'tails\\n')\n    fse.outputFileSync(path.join(TEST_DIR, 'a-folder/another-folder/file3'), 'knuckles\\n')\n  })\n\n  afterEach(() => fse.removeSync(TEST_DIR))\n\n  it('should not move if src and dest are the same', () => {\n    const src = `${TEST_DIR}/a-file`\n    const dest = `${TEST_DIR}/a-file`\n\n    let errThrown = false\n    try {\n      fse.moveSync(src, dest)\n    } catch (err) {\n      assert.strictEqual(err.message, 'Source and destination must not be the same.')\n      errThrown = true\n    } finally {\n      assert(errThrown)\n    }\n\n    // assert src not affected\n    const contents = fs.readFileSync(src, 'utf8')\n    const expected = /^sonic the hedgehog\\r?\\n$/\n    assert(contents.match(expected))\n  })\n\n  it('should error if src and dest are the same and src does not exist', () => {\n    const src = `${TEST_DIR}/non-existent`\n    const dest = src\n    assert.throws(() => fse.moveSync(src, dest))\n  })\n\n  it('should rename a file on the same device', () => {\n    const src = `${TEST_DIR}/a-file`\n    const dest = `${TEST_DIR}/a-file-dest`\n\n    fse.moveSync(src, dest)\n\n    const contents = fs.readFileSync(dest, 'utf8')\n    const expected = /^sonic the hedgehog\\r?\\n$/\n    assert(contents.match(expected))\n  })\n\n  it('should not overwrite the destination by default', () => {\n    const src = `${TEST_DIR}/a-file`\n    const dest = `${TEST_DIR}/a-folder/another-file`\n\n    // verify file exists already\n    assert(fs.existsSync(dest))\n\n    try {\n      fse.moveSync(src, dest)\n    } catch (err) {\n      assert.strictEqual(err.message, 'dest already exists.')\n    }\n  })\n\n  it('should not overwrite if overwrite = false', () => {\n    const src = `${TEST_DIR}/a-file`\n    const dest = `${TEST_DIR}/a-folder/another-file`\n\n    // verify file exists already\n    assert(fs.existsSync(dest))\n\n    try {\n      fse.moveSync(src, dest, { overwrite: false })\n    } catch (err) {\n      assert.strictEqual(err.message, 'dest already exists.')\n    }\n  })\n\n  it('should overwrite file if overwrite = true', () => {\n    const src = `${TEST_DIR}/a-file`\n    const dest = `${TEST_DIR}/a-folder/another-file`\n\n    // verify file exists already\n    assert(fs.existsSync(dest))\n\n    fse.moveSync(src, dest, { overwrite: true })\n\n    const contents = fs.readFileSync(dest, 'utf8')\n    const expected = /^sonic the hedgehog\\r?\\n$/\n    assert.ok(contents.match(expected))\n  })\n\n  it('should overwrite the destination directory if overwrite = true', () => {\n    // Create src\n    const src = path.join(TEST_DIR, 'src')\n    fse.ensureDirSync(src)\n    fse.mkdirsSync(path.join(src, 'some-folder'))\n    fs.writeFileSync(path.join(src, 'some-file'), 'hi')\n\n    const dest = path.join(TEST_DIR, 'a-folder')\n\n    // verify dest has stuff in it\n    const pathsBefore = fs.readdirSync(dest)\n    assert(pathsBefore.indexOf('another-file') >= 0)\n    assert(pathsBefore.indexOf('another-folder') >= 0)\n\n    fse.moveSync(src, dest, { overwrite: true })\n\n    // verify dest does not have old stuff\n    const pathsAfter = fs.readdirSync(dest)\n    assert.strictEqual(pathsAfter.indexOf('another-file'), -1)\n    assert.strictEqual(pathsAfter.indexOf('another-folder'), -1)\n\n    // verify dest has new stuff\n    assert(pathsAfter.indexOf('some-file') >= 0)\n    assert(pathsAfter.indexOf('some-folder') >= 0)\n  })\n\n  it('should create directory structure by default', () => {\n    const src = `${TEST_DIR}/a-file`\n    const dest = `${TEST_DIR}/does/not/exist/a-file-dest`\n\n    // verify dest directory does not exist\n    assert(!fs.existsSync(path.dirname(dest)))\n\n    fse.moveSync(src, dest)\n\n    const contents = fs.readFileSync(dest, 'utf8')\n    const expected = /^sonic the hedgehog\\r?\\n$/\n    assert(contents.match(expected))\n  })\n\n  it('should work across devices', () => {\n    const src = `${TEST_DIR}/a-file`\n    const dest = `${TEST_DIR}/a-file-dest`\n\n    setUpMockFs('EXDEV')\n\n    fse.moveSync(src, dest)\n\n    const contents = fs.readFileSync(dest, 'utf8')\n    const expected = /^sonic the hedgehog\\r?\\n$/\n    assert(contents.match(expected))\n    tearDownMockFs()\n  })\n\n  it('should move folders', () => {\n    const src = `${TEST_DIR}/a-folder`\n    const dest = `${TEST_DIR}/a-folder-dest`\n\n    // verify it doesn't exist\n    assert(!fs.existsSync(dest))\n\n    fse.moveSync(src, dest)\n\n    const contents = fs.readFileSync(dest + '/another-file', 'utf8')\n    const expected = /^tails\\r?\\n$/\n    assert(contents.match(expected))\n  })\n\n  it('should overwrite folders across devices', () => {\n    const src = `${TEST_DIR}/a-folder`\n    const dest = `${TEST_DIR}/a-folder-dest`\n    fs.mkdirSync(dest)\n\n    setUpMockFs('EXDEV')\n\n    fse.moveSync(src, dest, { overwrite: true })\n\n    const contents = fs.readFileSync(dest + '/another-folder/file3', 'utf8')\n    const expected = /^knuckles\\r?\\n$/\n    assert(contents.match(expected))\n    tearDownMockFs()\n  })\n\n  it('should move folders across devices with EXDEV error', () => {\n    const src = `${TEST_DIR}/a-folder`\n    const dest = `${TEST_DIR}/a-folder-dest`\n\n    setUpMockFs('EXDEV')\n\n    fse.moveSync(src, dest)\n\n    const contents = fs.readFileSync(dest + '/another-folder/file3', 'utf8')\n    const expected = /^knuckles\\r?\\n$/\n    assert(contents.match(expected))\n    tearDownMockFs()\n  })\n\n  describe('clobber', () => {\n    it('should be an alias for overwrite', () => {\n      const src = `${TEST_DIR}/a-file`\n      const dest = `${TEST_DIR}/a-folder/another-file`\n\n      // verify file exists already\n      assert(fs.existsSync(dest))\n\n      fse.moveSync(src, dest, { clobber: true })\n\n      const contents = fs.readFileSync(dest, 'utf8')\n      const expected = /^sonic the hedgehog\\r?\\n$/\n      assert(contents.match(expected))\n    })\n  })\n\n  describe('> when trying to move a folder into itself', () => {\n    it('should produce an error', () => {\n      const SRC_DIR = path.join(TEST_DIR, 'src')\n      const DEST_DIR = path.join(TEST_DIR, 'src', 'dest')\n\n      assert(!fs.existsSync(SRC_DIR))\n      fs.mkdirSync(SRC_DIR)\n      assert(fs.existsSync(SRC_DIR))\n\n      try {\n        fse.moveSync(SRC_DIR, DEST_DIR)\n      } catch (err) {\n        assert(err.message, `Cannot move ${SRC_DIR} into itself ${DEST_DIR}.`)\n        assert(fs.existsSync(SRC_DIR))\n        assert(!fs.existsSync(DEST_DIR))\n      }\n    })\n  })\n\n  describe('> when trying to move a file into its parent subdirectory', () => {\n    it('should move successfully', () => {\n      const src = `${TEST_DIR}/a-file`\n      const dest = `${TEST_DIR}/dest/a-file-dest`\n\n      fse.moveSync(src, dest)\n\n      const contents = fs.readFileSync(dest, 'utf8')\n      const expected = /^sonic the hedgehog\\r?\\n$/\n      assert(contents.match(expected))\n    })\n  })\n\n  describeIfWindows('> when dest parent is root', () => {\n    let dest\n\n    afterEach(() => fse.removeSync(dest))\n\n    it('should not create parent directory', () => {\n      const src = path.join(TEST_DIR, 'a-file')\n      dest = path.join(path.parse(TEST_DIR).root, 'another-file')\n\n      fse.moveSync(src, dest)\n\n      const contents = fs.readFileSync(dest, 'utf8')\n      const expected = /^sonic the hedgehog\\r?\\n$/\n      assert(contents.match(expected))\n    })\n  })\n\n  ifCrossDeviceEnabled(describe)('> when actually trying to move a folder across devices', () => {\n    describe('> just the folder', () => {\n      it('should move the folder', () => {\n        const src = path.join(differentDevice, 'some/weird/dir-really-weird')\n        const dest = path.join(TEST_DIR, 'device-weird')\n\n        if (!fs.existsSync(src)) fse.mkdirpSync(src)\n        assert(!fs.existsSync(dest))\n        assert(fs.lstatSync(src).isDirectory())\n\n        fse.moveSync(src, dest)\n\n        assert(fs.existsSync(dest))\n        assert(fs.lstatSync(dest).isDirectory())\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/move/__tests__/move.test.js",
    "content": "'use strict'\n\nconst fs = require('../../fs')\nconst os = require('os')\nconst fse = require('../../')\nconst path = require('path')\nconst assert = require('assert')\nconst { differentDevice, ifCrossDeviceEnabled } = require('./cross-device-utils')\n\n/* global afterEach, beforeEach, describe, it */\n\nconst describeIfWindows = process.platform === 'win32' ? describe : describe.skip\n\nfunction createAsyncErrFn (errCode) {\n  async function fn () {\n    fn.callCount++\n    const err = new Error()\n    err.code = errCode\n\n    return Promise.reject(err)\n  }\n  fn.callCount = 0\n  return fn\n}\n\nconst originalRename = fs.rename\n\nfunction setUpMockFs (errCode) {\n  fs.rename = createAsyncErrFn(errCode)\n}\n\nfunction tearDownMockFs () {\n  fs.rename = originalRename\n}\n\ndescribe('+ move()', () => {\n  let TEST_DIR\n\n  beforeEach(() => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move')\n\n    fse.emptyDirSync(TEST_DIR)\n\n    // Create fixtures:\n    fs.writeFileSync(path.join(TEST_DIR, 'a-file'), 'sonic the hedgehog\\n')\n    fs.mkdirSync(path.join(TEST_DIR, 'a-folder'))\n    fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-file'), 'tails\\n')\n    fs.mkdirSync(path.join(TEST_DIR, 'a-folder/another-folder'))\n    fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-folder/file3'), 'knuckles\\n')\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('> when overwrite = true', () => {\n    it('should overwrite file', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-folder', 'another-file')\n\n      // verify file exists already\n      assert(fs.existsSync(dest))\n\n      fse.move(src, dest, { overwrite: true }, err => {\n        assert.ifError(err)\n        fs.readFile(dest, 'utf8', (err, contents) => {\n          const expected = /^sonic the hedgehog\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          done()\n        })\n      })\n    })\n\n    it('should overwrite the destination directory', done => {\n      // Create src\n      const src = path.join(TEST_DIR, 'src')\n      fse.ensureDirSync(src)\n      fse.mkdirsSync(path.join(src, 'some-folder'))\n      fs.writeFileSync(path.join(src, 'some-file'), 'hi')\n\n      const dest = path.join(TEST_DIR, 'a-folder')\n\n      // verify dest has stuff in it\n      const paths = fs.readdirSync(dest)\n      assert(paths.indexOf('another-file') >= 0)\n      assert(paths.indexOf('another-folder') >= 0)\n\n      fse.move(src, dest, { overwrite: true }, err => {\n        assert.ifError(err)\n\n        // verify dest does not have old stuff\n        const paths = fs.readdirSync(dest)\n        assert.strictEqual(paths.indexOf('another-file'), -1)\n        assert.strictEqual(paths.indexOf('another-folder'), -1)\n\n        // verify dest has new stuff\n        assert(paths.indexOf('some-file') >= 0)\n        assert(paths.indexOf('some-folder') >= 0)\n\n        done()\n      })\n    })\n\n    it('should overwrite folders across devices', done => {\n      const src = path.join(TEST_DIR, 'a-folder')\n      const dest = path.join(TEST_DIR, 'a-folder-dest')\n\n      fs.mkdirSync(dest)\n\n      setUpMockFs('EXDEV')\n\n      fse.move(src, dest, { overwrite: true }, err => {\n        assert.ifError(err)\n        assert.strictEqual(fs.rename.callCount, 1)\n\n        fs.readFile(path.join(dest, 'another-folder', 'file3'), 'utf8', (err, contents) => {\n          const expected = /^knuckles\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          tearDownMockFs()\n          done()\n        })\n      })\n    })\n  })\n\n  describe('> when overwrite = false', () => {\n    it('should rename a file on the same device', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-file-dest')\n\n      fse.move(src, dest, err => {\n        assert.ifError(err)\n        fs.readFile(dest, 'utf8', (err, contents) => {\n          const expected = /^sonic the hedgehog\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          done()\n        })\n      })\n    })\n\n    it('should support promises', async () => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-file-dest')\n\n      await fse.move(src, dest)\n\n      const contents = fs.readFileSync(dest, 'utf8')\n      const expected = /^sonic the hedgehog\\r?\\n$/\n      assert.ok(contents.match(expected))\n    })\n\n    it('should not move a file if source and destination are the same', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = src\n\n      fse.move(src, dest, err => {\n        assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        done()\n      })\n    })\n\n    it('should error if source and destination are the same and source does not exist', done => {\n      const src = path.join(TEST_DIR, 'non-existent')\n      const dest = src\n\n      fse.move(src, dest, err => {\n        assert(err)\n        done()\n      })\n    })\n\n    it('should not move a directory if source and destination are the same', done => {\n      const src = path.join(TEST_DIR, 'a-folder')\n      const dest = src\n\n      fse.move(src, dest, err => {\n        assert.strictEqual(err.message, 'Source and destination must not be the same.')\n        done()\n      })\n    })\n\n    it('should not overwrite the destination by default', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-folder', 'another-file')\n\n      // verify file exists already\n      assert(fs.existsSync(dest))\n\n      fse.move(src, dest, err => {\n        assert.strictEqual(err.message, 'dest already exists.')\n        done()\n      })\n    })\n\n    it('should not overwrite if overwrite = false', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-folder', 'another-file')\n\n      // verify file exists already\n      assert(fs.existsSync(dest))\n\n      fse.move(src, dest, { overwrite: false }, err => {\n        assert.strictEqual(err.message, 'dest already exists.')\n        done()\n      })\n    })\n\n    it('should create directory structure by default', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'does', 'not', 'exist', 'a-file-dest')\n\n      // verify dest directory does not exist\n      assert(!fs.existsSync(path.dirname(dest)))\n\n      fse.move(src, dest, err => {\n        assert.ifError(err)\n        fs.readFile(dest, 'utf8', (err, contents) => {\n          const expected = /^sonic the hedgehog\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          done()\n        })\n      })\n    })\n\n    it('should work across devices', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-file-dest')\n\n      setUpMockFs('EXDEV')\n\n      fse.move(src, dest, err => {\n        assert.ifError(err)\n        assert.strictEqual(fs.rename.callCount, 1)\n\n        fs.readFile(dest, 'utf8', (err, contents) => {\n          const expected = /^sonic the hedgehog\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          tearDownMockFs()\n          done()\n        })\n      })\n    })\n\n    it('should move folders', done => {\n      const src = path.join(TEST_DIR, 'a-folder')\n      const dest = path.join(TEST_DIR, 'a-folder-dest')\n\n      // verify it doesn't exist\n      assert(!fs.existsSync(dest))\n\n      fse.move(src, dest, err => {\n        assert.ifError(err)\n        fs.readFile(path.join(dest, 'another-file'), 'utf8', (err, contents) => {\n          const expected = /^tails\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          done()\n        })\n      })\n    })\n\n    it('should move folders across devices with EXDEV error', done => {\n      const src = path.join(TEST_DIR, 'a-folder')\n      const dest = path.join(TEST_DIR, 'a-folder-dest')\n\n      setUpMockFs('EXDEV')\n\n      fse.move(src, dest, err => {\n        assert.ifError(err)\n        assert.strictEqual(fs.rename.callCount, 1)\n\n        fs.readFile(path.join(dest, 'another-folder', 'file3'), 'utf8', (err, contents) => {\n          const expected = /^knuckles\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          tearDownMockFs()\n          done()\n        })\n      })\n    })\n  })\n\n  describe('> when opts is explicit undefined', () => {\n    it('works with callbacks', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-file-dest')\n\n      fse.move(src, dest, undefined, err => {\n        assert.ifError(err)\n        fs.readFile(dest, 'utf8', (err, contents) => {\n          const expected = /^sonic the hedgehog\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          done()\n        })\n      })\n    })\n\n    it('works with promises', async () => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-file-dest')\n\n      await fse.move(src, dest, undefined)\n\n      const contents = fs.readFileSync(dest, 'utf8')\n      const expected = /^sonic the hedgehog\\r?\\n$/\n      assert.ok(contents.match(expected))\n    })\n  })\n\n  describeIfWindows('> when dest parent is root', () => {\n    let dest\n\n    afterEach(done => fse.remove(dest, done))\n\n    it('should not create parent directory', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      dest = path.join(path.parse(TEST_DIR).root, 'another-file')\n\n      fse.move(src, dest, err => {\n        assert.ifError(err)\n        fs.readFile(dest, 'utf8', (err, contents) => {\n          const expected = /^sonic the hedgehog\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          done()\n        })\n      })\n    })\n  })\n\n  describe('> clobber', () => {\n    it('should be an alias for overwrite', done => {\n      const src = path.join(TEST_DIR, 'a-file')\n      const dest = path.join(TEST_DIR, 'a-folder', 'another-file')\n\n      // verify file exists already\n      assert(fs.existsSync(dest))\n\n      fse.move(src, dest, { clobber: true }, err => {\n        assert.ifError(err)\n        fs.readFile(dest, 'utf8', (err, contents) => {\n          const expected = /^sonic the hedgehog\\r?\\n$/\n          assert.ifError(err)\n          assert.ok(contents.match(expected))\n          done()\n        })\n      })\n    })\n  })\n\n  describe('> when trying to move a folder into itself', () => {\n    it('should produce an error', done => {\n      const SRC_DIR = path.join(TEST_DIR, 'test')\n      const DEST_DIR = path.join(TEST_DIR, 'test', 'test')\n\n      assert(!fs.existsSync(SRC_DIR))\n      fs.mkdirSync(SRC_DIR)\n      assert(fs.existsSync(SRC_DIR))\n\n      fse.move(SRC_DIR, DEST_DIR, err => {\n        assert(fs.existsSync(SRC_DIR))\n        assert.strictEqual(err.message, `Cannot move '${SRC_DIR}' to a subdirectory of itself, '${DEST_DIR}'.`)\n        done()\n      })\n    })\n  })\n\n  // tested on Linux ubuntu 3.13.0-32-generic #57-Ubuntu SMP i686 i686 GNU/Linux\n  // this won't trigger a bug on Mac OS X Yosimite with a USB drive (/Volumes)\n  // see issue #108\n  ifCrossDeviceEnabled(describe)('> when actually trying to move a folder across devices', () => {\n    describe('>> just the folder', () => {\n      it('should move the folder', done => {\n        const src = path.join(differentDevice, 'some/weird/dir-really-weird')\n        const dest = path.join(TEST_DIR, 'device-weird')\n\n        if (!fs.existsSync(src)) {\n          fse.mkdirpSync(src)\n        }\n\n        assert(!fs.existsSync(dest))\n\n        assert(fs.lstatSync(src).isDirectory())\n\n        fse.move(src, dest, err => {\n          assert.ifError(err)\n          assert(fs.existsSync(dest))\n          assert(fs.lstatSync(dest).isDirectory())\n          done()\n        })\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/move/index.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nmodule.exports = {\n  move: u(require('./move')),\n  moveSync: require('./move-sync')\n}\n"
  },
  {
    "path": "lib/move/move-sync.js",
    "content": "'use strict'\n\nconst fs = require('graceful-fs')\nconst path = require('path')\nconst copySync = require('../copy').copySync\nconst removeSync = require('../remove').removeSync\nconst mkdirpSync = require('../mkdirs').mkdirpSync\nconst stat = require('../util/stat')\n\nfunction moveSync (src, dest, opts) {\n  opts = opts || {}\n  const overwrite = opts.overwrite || opts.clobber || false\n\n  const { srcStat, isChangingCase = false } = stat.checkPathsSync(src, dest, 'move', opts)\n  stat.checkParentPathsSync(src, srcStat, dest, 'move')\n  if (!isParentRoot(dest)) mkdirpSync(path.dirname(dest))\n  return doRename(src, dest, overwrite, isChangingCase)\n}\n\nfunction isParentRoot (dest) {\n  const parent = path.dirname(dest)\n  const parsedPath = path.parse(parent)\n  return parsedPath.root === parent\n}\n\nfunction doRename (src, dest, overwrite, isChangingCase) {\n  if (isChangingCase) return rename(src, dest, overwrite)\n  if (overwrite) {\n    removeSync(dest)\n    return rename(src, dest, overwrite)\n  }\n  if (fs.existsSync(dest)) throw new Error('dest already exists.')\n  return rename(src, dest, overwrite)\n}\n\nfunction rename (src, dest, overwrite) {\n  try {\n    fs.renameSync(src, dest)\n  } catch (err) {\n    if (err.code !== 'EXDEV') throw err\n    return moveAcrossDevice(src, dest, overwrite)\n  }\n}\n\nfunction moveAcrossDevice (src, dest, overwrite) {\n  const opts = {\n    overwrite,\n    errorOnExist: true,\n    preserveTimestamps: true\n  }\n  copySync(src, dest, opts)\n  return removeSync(src)\n}\n\nmodule.exports = moveSync\n"
  },
  {
    "path": "lib/move/move.js",
    "content": "'use strict'\n\nconst fs = require('../fs')\nconst path = require('path')\nconst { copy } = require('../copy')\nconst { remove } = require('../remove')\nconst { mkdirp } = require('../mkdirs')\nconst { pathExists } = require('../path-exists')\nconst stat = require('../util/stat')\n\nasync function move (src, dest, opts = {}) {\n  const overwrite = opts.overwrite || opts.clobber || false\n\n  const { srcStat, isChangingCase = false } = await stat.checkPaths(src, dest, 'move', opts)\n\n  await stat.checkParentPaths(src, srcStat, dest, 'move')\n\n  // If the parent of dest is not root, make sure it exists before proceeding\n  const destParent = path.dirname(dest)\n  const parsedParentPath = path.parse(destParent)\n  if (parsedParentPath.root !== destParent) {\n    await mkdirp(destParent)\n  }\n\n  return doRename(src, dest, overwrite, isChangingCase)\n}\n\nasync function doRename (src, dest, overwrite, isChangingCase) {\n  if (!isChangingCase) {\n    if (overwrite) {\n      await remove(dest)\n    } else if (await pathExists(dest)) {\n      throw new Error('dest already exists.')\n    }\n  }\n\n  try {\n    // Try w/ rename first, and try copy + remove if EXDEV\n    await fs.rename(src, dest)\n  } catch (err) {\n    if (err.code !== 'EXDEV') {\n      throw err\n    }\n    await moveAcrossDevice(src, dest, overwrite)\n  }\n}\n\nasync function moveAcrossDevice (src, dest, overwrite) {\n  const opts = {\n    overwrite,\n    errorOnExist: true,\n    preserveTimestamps: true\n  }\n\n  await copy(src, dest, opts)\n  return remove(src)\n}\n\nmodule.exports = move\n"
  },
  {
    "path": "lib/output-file/__tests__/output.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global afterEach, beforeEach, describe, it */\n\ndescribe('output', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'output')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ outputFile', () => {\n    describe('> when the file and directory does not exist', () => {\n      it('should create the file', done => {\n        const file = path.join(TEST_DIR, Math.random() + 't-ne', Math.random() + '.txt')\n        assert(!fs.existsSync(file))\n        fse.outputFile(file, 'hi jp', err => {\n          assert.ifError(err)\n          assert(fs.existsSync(file))\n          assert.strictEqual(fs.readFileSync(file, 'utf8'), 'hi jp')\n          done()\n        })\n      })\n      it('should support promises', () => {\n        const file = path.join(TEST_DIR, Math.random() + 't-ne', Math.random() + '.txt')\n        assert(!fs.existsSync(file))\n        return fse.outputFile(file, 'hi jp')\n      })\n    })\n\n    describe('> when the file does exist', () => {\n      it('should still modify the file', done => {\n        const file = path.join(TEST_DIR, Math.random() + 't-e', Math.random() + '.txt')\n        fse.mkdirsSync(path.dirname(file))\n        fs.writeFileSync(file, 'hello world')\n        fse.outputFile(file, 'hello jp', err => {\n          if (err) return done(err)\n          assert.strictEqual(fs.readFileSync(file, 'utf8'), 'hello jp')\n          done()\n        })\n      })\n    })\n  })\n\n  describe('+ outputFileSync', () => {\n    describe('> when the file and directory does not exist', () => {\n      it('should create the file', () => {\n        const file = path.join(TEST_DIR, Math.random() + 'ts-ne', Math.random() + '.txt')\n        assert(!fs.existsSync(file))\n        fse.outputFileSync(file, 'hello man')\n        assert(fs.existsSync(file))\n        assert.strictEqual(fs.readFileSync(file, 'utf8'), 'hello man')\n      })\n    })\n\n    describe('> when the file does exist', () => {\n      it('should still modify the file', () => {\n        const file = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt')\n        fse.mkdirsSync(path.dirname(file))\n        fs.writeFileSync(file, 'hello world')\n        fse.outputFileSync(file, 'hello man')\n        assert.strictEqual(fs.readFileSync(file, 'utf8'), 'hello man')\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/output-file/index.js",
    "content": "'use strict'\n\nconst u = require('universalify').fromPromise\nconst fs = require('../fs')\nconst path = require('path')\nconst mkdir = require('../mkdirs')\nconst pathExists = require('../path-exists').pathExists\n\nasync function outputFile (file, data, encoding = 'utf-8') {\n  const dir = path.dirname(file)\n\n  if (!(await pathExists(dir))) {\n    await mkdir.mkdirs(dir)\n  }\n\n  return fs.writeFile(file, data, encoding)\n}\n\nfunction outputFileSync (file, ...args) {\n  const dir = path.dirname(file)\n  if (!fs.existsSync(dir)) {\n    mkdir.mkdirsSync(dir)\n  }\n\n  fs.writeFileSync(file, ...args)\n}\n\nmodule.exports = {\n  outputFile: u(outputFile),\n  outputFileSync\n}\n"
  },
  {
    "path": "lib/path-exists/__tests__/path-exists-sync.test.js",
    "content": "'use strict'\n/* eslint-env mocha */\n\nconst fs = require('../..')\nconst path = require('path')\nconst os = require('os')\nconst assert = require('assert')\n\ndescribe('pathExists()', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'path-exists')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  it('should return false if file does not exist', () => {\n    assert(!fs.pathExistsSync(path.join(TEST_DIR, 'somefile')))\n  })\n\n  it('should return true if file does exist', () => {\n    const file = path.join(TEST_DIR, 'exists')\n    fs.ensureFileSync(file)\n    assert(fs.pathExistsSync(file))\n  })\n})\n"
  },
  {
    "path": "lib/path-exists/__tests__/path-exists.test.js",
    "content": "'use strict'\n/* eslint-env mocha */\n\nconst fs = require('../..')\nconst path = require('path')\nconst os = require('os')\nconst assert = require('assert')\n\ndescribe('pathExists()', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'path-exists')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  it('should return false if file does not exist', () => {\n    return fs.pathExists(path.join(TEST_DIR, 'somefile'))\n      .then(exists => assert(!exists))\n  })\n\n  it('should return true if file does exist', () => {\n    const file = path.join(TEST_DIR, 'exists')\n    fs.ensureFileSync(file)\n    return fs.pathExists(file)\n      .then(exists => assert(exists))\n  })\n\n  it('should pass an empty error parameter to the callback', done => {\n    const file = path.join(TEST_DIR, 'exists')\n    fs.ensureFileSync(file)\n    fs.pathExists(file, (err, exists) => {\n      assert.ifError(err)\n      assert(exists)\n      done()\n    })\n  })\n})\n"
  },
  {
    "path": "lib/path-exists/index.js",
    "content": "'use strict'\nconst u = require('universalify').fromPromise\nconst fs = require('../fs')\n\nfunction pathExists (path) {\n  return fs.access(path).then(() => true).catch(() => false)\n}\n\nmodule.exports = {\n  pathExists: u(pathExists),\n  pathExistsSync: fs.existsSync\n}\n"
  },
  {
    "path": "lib/remove/__tests__/remove-dir.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global beforeEach, describe, it */\n\ndescribe('remove / async / dir', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'remove-async-dir')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  describe('> when dir does not exist', () => {\n    it('should not throw an error', done => {\n      const someDir = path.join(TEST_DIR, 'some-dir/')\n      assert.strictEqual(fs.existsSync(someDir), false)\n      fse.remove(someDir, err => {\n        assert.ifError(err)\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/remove/__tests__/remove-file.test.js",
    "content": "// todo\n"
  },
  {
    "path": "lib/remove/__tests__/remove-sync-dir.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global beforeEach, describe, it */\n\ndescribe('remove/sync', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'remove-sync')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  describe('+ removeSync()', () => {\n    it('should delete directories and files synchronously', () => {\n      assert(fs.existsSync(TEST_DIR))\n      fs.writeFileSync(path.join(TEST_DIR, 'somefile'), 'somedata')\n      fse.removeSync(TEST_DIR)\n      assert(!fs.existsSync(TEST_DIR))\n    })\n\n    it('should delete an empty directory synchronously', () => {\n      assert(fs.existsSync(TEST_DIR))\n      fse.removeSync(TEST_DIR)\n      assert(!fs.existsSync(TEST_DIR))\n    })\n  })\n})\n"
  },
  {
    "path": "lib/remove/__tests__/remove-sync-file.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\n\n/* global beforeEach, describe, it */\n\ndescribe('remove/sync', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'remove-sync')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  describe('+ removeSync()', () => {\n    it('should delete a file synchronously', () => {\n      const file = path.join(TEST_DIR, 'file')\n      fs.writeFileSync(file, 'hello')\n      assert(fs.existsSync(file))\n      fse.removeSync(file)\n      assert(!fs.existsSync(file))\n    })\n  })\n})\n"
  },
  {
    "path": "lib/remove/__tests__/remove.test.js",
    "content": "'use strict'\n\nconst assert = require('assert')\nconst fs = require('fs')\nconst os = require('os')\nconst path = require('path')\nconst randomBytes = require('crypto').randomBytes\nconst fse = require('../..')\n\n/* global afterEach, beforeEach, describe, it */\n\nlet TEST_DIR\n\nfunction buildFixtureDir () {\n  const buf = randomBytes(5)\n  const baseDir = path.join(TEST_DIR, `TEST_fs-extra_remove-${Date.now()}`)\n\n  fs.mkdirSync(baseDir)\n  fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)\n  fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)\n\n  const subDir = path.join(TEST_DIR, Math.random() + '')\n  fs.mkdirSync(subDir)\n  fs.writeFileSync(path.join(subDir, Math.random() + ''), buf)\n  return baseDir\n}\n\ndescribe('remove', () => {\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'remove')\n    fse.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fse.remove(TEST_DIR, done))\n\n  describe('+ remove()', () => {\n    it('should delete an empty directory', done => {\n      assert(fs.existsSync(TEST_DIR))\n      fse.remove(TEST_DIR, err => {\n        assert.ifError(err)\n        assert(!fs.existsSync(TEST_DIR))\n        done()\n      })\n    })\n\n    it('should delete a directory full of directories and files', done => {\n      buildFixtureDir()\n      assert(fs.existsSync(TEST_DIR))\n      fse.remove(TEST_DIR, err => {\n        assert.ifError(err)\n        assert(!fs.existsSync(TEST_DIR))\n        done()\n      })\n    })\n\n    it('should delete a file', done => {\n      const file = path.join(TEST_DIR, 'file')\n      fs.writeFileSync(file, 'hello')\n\n      assert(fs.existsSync(file))\n      fse.remove(file, err => {\n        assert.ifError(err)\n        assert(!fs.existsSync(file))\n        done()\n      })\n    })\n\n    it('should delete without a callback', done => {\n      const file = path.join(TEST_DIR, 'file')\n      fs.writeFileSync(file, 'hello')\n\n      assert(fs.existsSync(file))\n      let existsChecker = setInterval(() => {\n        fse.pathExists(file, (err, itDoes) => {\n          assert.ifError(err)\n          if (!itDoes && existsChecker) {\n            clearInterval(existsChecker)\n            existsChecker = null\n            done()\n          }\n        })\n      }, 25)\n      fse.remove(file)\n    })\n\n    it('shouldn’t delete glob matches', function (done) {\n      const file = path.join(TEST_DIR, 'file?')\n      try {\n        fs.writeFileSync(file, 'hello')\n      } catch (ex) {\n        if (ex.code === 'ENOENT') return this.skip('Windows does not support filenames with ‘?’ or ‘*’ in them.')\n        throw ex\n      }\n\n      const wrongFile = path.join(TEST_DIR, 'file1')\n      fs.writeFileSync(wrongFile, 'yo')\n\n      assert(fs.existsSync(file))\n      assert(fs.existsSync(wrongFile))\n      fse.remove(file, err => {\n        assert.ifError(err)\n        assert(!fs.existsSync(file))\n        assert(fs.existsSync(wrongFile))\n        done()\n      })\n    })\n\n    it('shouldn’t delete glob matches when file doesn’t exist', done => {\n      const nonexistentFile = path.join(TEST_DIR, 'file?')\n\n      const wrongFile = path.join(TEST_DIR, 'file1')\n      fs.writeFileSync(wrongFile, 'yo')\n\n      assert(!fs.existsSync(nonexistentFile))\n      assert(fs.existsSync(wrongFile))\n      fse.remove(nonexistentFile, err => {\n        assert.ifError(err)\n        assert(!fs.existsSync(nonexistentFile))\n        assert(fs.existsSync(wrongFile))\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/remove/index.js",
    "content": "'use strict'\n\nconst fs = require('graceful-fs')\nconst u = require('universalify').fromCallback\n\nfunction remove (path, callback) {\n  fs.rm(path, { recursive: true, force: true }, callback)\n}\n\nfunction removeSync (path) {\n  fs.rmSync(path, { recursive: true, force: true })\n}\n\nmodule.exports = {\n  remove: u(remove),\n  removeSync\n}\n"
  },
  {
    "path": "lib/util/__tests__/stat.test.js",
    "content": "'use strict'\n\nconst fs = require('../..')\nconst os = require('os')\nconst path = require('path')\nconst assert = require('assert')\nconst stat = require('../stat.js')\n\n/* global beforeEach, afterEach, describe, it */\n\ndescribe('util/stat', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'util-stat')\n    fs.emptyDir(TEST_DIR, done)\n  })\n\n  afterEach(done => fs.remove(TEST_DIR, done))\n\n  describe('should use stats with bigint type', () => {\n    it('stat.checkPaths()', () => {\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n      fs.ensureFileSync(src)\n      fs.ensureFileSync(dest)\n      stat.checkPaths(src, dest, 'copy', {}, (err, stats) => {\n        assert.ifError(err)\n        assert.strictEqual(typeof stats.srcStat.ino, 'bigint')\n      })\n    })\n\n    it('stat.checkPathsSync()', () => {\n      const src = path.join(TEST_DIR, 'src')\n      const dest = path.join(TEST_DIR, 'dest')\n      fs.ensureFileSync(src)\n      fs.ensureFileSync(dest)\n      const { srcStat } = stat.checkPathsSync(src, dest, 'copy', {})\n      assert.strictEqual(typeof srcStat.ino, 'bigint')\n    })\n  })\n\n  describe('should stop at src or root path and not throw max call stack size error', () => {\n    it('stat.checkParentPaths()', () => {\n      const src = path.join(TEST_DIR, 'src')\n      let dest = path.join(TEST_DIR, 'dest')\n      fs.ensureFileSync(src)\n      fs.ensureFileSync(dest)\n      dest = path.basename(dest)\n      const srcStat = fs.statSync(src)\n      stat.checkParentPaths(src, srcStat, dest, 'copy', err => {\n        assert.ifError(err)\n      })\n    })\n\n    it('stat.checkParentPathsSync()', () => {\n      const src = path.join(TEST_DIR, 'src')\n      let dest = path.join(TEST_DIR, 'dest')\n      fs.ensureFileSync(src)\n      fs.ensureFileSync(dest)\n      dest = path.basename(dest)\n      const srcStat = fs.statSync(src)\n      stat.checkParentPathsSync(src, srcStat, dest, 'copy')\n    })\n  })\n\n  describe('should get correct identical result when stat.ino or stat.dev is 0n', () => {\n    it('stat.areIdentical', () => {\n      assert.ok(stat.areIdentical({ ino: 0n, dev: 0n }, { ino: 0n, dev: 0n }))\n      assert.ok(stat.areIdentical({ ino: 1n, dev: 0n }, { ino: 1n, dev: 0n }))\n      assert.ok(stat.areIdentical({ ino: 0n, dev: 1n }, { ino: 0n, dev: 1n }))\n      assert.ok(stat.areIdentical({ ino: 1n, dev: 1n }, { ino: 1n, dev: 1n }))\n      assert.ok(!stat.areIdentical({ ino: 2n, dev: 0n }, { ino: 1n, dev: 0n }))\n      assert.ok(!stat.areIdentical({ ino: 0n, dev: 2n }, { ino: 0n, dev: 1n }))\n      assert.ok(!stat.areIdentical({ ino: 2n, dev: 1n }, { ino: 1n, dev: 2n }))\n    })\n  })\n})\n"
  },
  {
    "path": "lib/util/__tests__/utimes.test.js",
    "content": "'use strict'\n\nconst fs = require('fs')\nconst os = require('os')\nconst fse = require('../..')\nconst path = require('path')\nconst assert = require('assert')\nconst proxyquire = require('proxyquire')\nconst u = require('universalify').fromCallback\n\nlet gracefulFsStub\nlet utimes\n\n/* global beforeEach, describe, it */\n\n// HFS, ext{2,3}, FAT do not\nfunction hasMillisResSync () {\n  let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))\n  tmpfile = path.join(os.tmpdir(), tmpfile)\n\n  // 550 millis past UNIX epoch\n  const d = new Date(1435410243862)\n  fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')\n  const fd = fs.openSync(tmpfile, 'r+')\n  fs.futimesSync(fd, d, d)\n  fs.closeSync(fd)\n  return fs.statSync(tmpfile).mtime > 1435410243000\n}\n\ndescribe('utimes', () => {\n  let TEST_DIR\n\n  beforeEach(done => {\n    TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'utimes')\n    fse.emptyDir(TEST_DIR, done)\n    // reset stubs\n    gracefulFsStub = {}\n    utimes = proxyquire('../utimes', { '../fs': gracefulFsStub })\n  })\n\n  describe('utimesMillis()', () => {\n    // see discussion https://github.com/jprichardson/node-fs-extra/pull/141\n    it('should set the utimes w/ millisecond precision', done => {\n      const tmpFile = path.join(TEST_DIR, 'someFile')\n      fs.writeFileSync(tmpFile, 'hello')\n\n      let stats = fs.lstatSync(tmpFile)\n\n      // Apr 21st, 2012\n      const awhileAgo = new Date(1334990868773)\n      const awhileAgoNoMillis = new Date(1334990868000)\n\n      assert.notDeepStrictEqual(stats.mtime, awhileAgo)\n      assert.notDeepStrictEqual(stats.atime, awhileAgo)\n\n      utimes.utimesMillis(tmpFile, awhileAgo, awhileAgo, err => {\n        assert.ifError(err)\n        stats = fs.statSync(tmpFile)\n        if (hasMillisResSync()) {\n          assert.deepStrictEqual(stats.mtime, awhileAgo)\n          assert.deepStrictEqual(stats.atime, awhileAgo)\n        } else {\n          assert.deepStrictEqual(stats.mtime, awhileAgoNoMillis)\n          assert.deepStrictEqual(stats.atime, awhileAgoNoMillis)\n        }\n        done()\n      })\n    })\n\n    it('should close open file desciptors after encountering an error', done => {\n      const fakeFd = Math.random()\n\n      gracefulFsStub.open = u((pathIgnored, flagsIgnored, modeIgnored, callback) => {\n        if (typeof modeIgnored === 'function') callback = modeIgnored\n        process.nextTick(() => callback(null, fakeFd))\n      })\n\n      let closeCalled = false\n      gracefulFsStub.close = u((fd, callback) => {\n        assert.strictEqual(fd, fakeFd)\n        closeCalled = true\n        if (callback) process.nextTick(callback)\n      })\n\n      let testError\n      gracefulFsStub.futimes = u((fd, atimeIgnored, mtimeIgnored, callback) => {\n        process.nextTick(() => {\n          testError = new Error('A test error')\n          callback(testError)\n        })\n      })\n\n      utimes.utimesMillis('ignored', 'ignored', 'ignored', err => {\n        assert.strictEqual(err, testError)\n        assert(closeCalled)\n        done()\n      })\n    })\n  })\n})\n"
  },
  {
    "path": "lib/util/async.js",
    "content": "'use strict'\n\n// https://github.com/jprichardson/node-fs-extra/issues/1056\n// Performing parallel operations on each item of an async iterator is\n// surprisingly hard; you need to have handlers in place to avoid getting an\n// UnhandledPromiseRejectionWarning.\n// NOTE: This function does not presently handle return values, only errors\nasync function asyncIteratorConcurrentProcess (iterator, fn) {\n  const promises = []\n  for await (const item of iterator) {\n    promises.push(\n      fn(item).then(\n        () => null,\n        (err) => err ?? new Error('unknown error')\n      )\n    )\n  }\n  await Promise.all(\n    promises.map((promise) =>\n      promise.then((possibleErr) => {\n        if (possibleErr !== null) throw possibleErr\n      })\n    )\n  )\n}\n\nmodule.exports = {\n  asyncIteratorConcurrentProcess\n}\n"
  },
  {
    "path": "lib/util/stat.js",
    "content": "'use strict'\n\nconst fs = require('../fs')\nconst path = require('path')\nconst u = require('universalify').fromPromise\n\nfunction getStats (src, dest, opts) {\n  const statFunc = opts.dereference\n    ? (file) => fs.stat(file, { bigint: true })\n    : (file) => fs.lstat(file, { bigint: true })\n  return Promise.all([\n    statFunc(src),\n    statFunc(dest).catch(err => {\n      if (err.code === 'ENOENT') return null\n      throw err\n    })\n  ]).then(([srcStat, destStat]) => ({ srcStat, destStat }))\n}\n\nfunction getStatsSync (src, dest, opts) {\n  let destStat\n  const statFunc = opts.dereference\n    ? (file) => fs.statSync(file, { bigint: true })\n    : (file) => fs.lstatSync(file, { bigint: true })\n  const srcStat = statFunc(src)\n  try {\n    destStat = statFunc(dest)\n  } catch (err) {\n    if (err.code === 'ENOENT') return { srcStat, destStat: null }\n    throw err\n  }\n  return { srcStat, destStat }\n}\n\nasync function checkPaths (src, dest, funcName, opts) {\n  const { srcStat, destStat } = await getStats(src, dest, opts)\n  if (destStat) {\n    if (areIdentical(srcStat, destStat)) {\n      const srcBaseName = path.basename(src)\n      const destBaseName = path.basename(dest)\n      if (funcName === 'move' &&\n        srcBaseName !== destBaseName &&\n        srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {\n        return { srcStat, destStat, isChangingCase: true }\n      }\n      throw new Error('Source and destination must not be the same.')\n    }\n    if (srcStat.isDirectory() && !destStat.isDirectory()) {\n      throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)\n    }\n    if (!srcStat.isDirectory() && destStat.isDirectory()) {\n      throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`)\n    }\n  }\n\n  if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {\n    throw new Error(errMsg(src, dest, funcName))\n  }\n\n  return { srcStat, destStat }\n}\n\nfunction checkPathsSync (src, dest, funcName, opts) {\n  const { srcStat, destStat } = getStatsSync(src, dest, opts)\n\n  if (destStat) {\n    if (areIdentical(srcStat, destStat)) {\n      const srcBaseName = path.basename(src)\n      const destBaseName = path.basename(dest)\n      if (funcName === 'move' &&\n        srcBaseName !== destBaseName &&\n        srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {\n        return { srcStat, destStat, isChangingCase: true }\n      }\n      throw new Error('Source and destination must not be the same.')\n    }\n    if (srcStat.isDirectory() && !destStat.isDirectory()) {\n      throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)\n    }\n    if (!srcStat.isDirectory() && destStat.isDirectory()) {\n      throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`)\n    }\n  }\n\n  if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {\n    throw new Error(errMsg(src, dest, funcName))\n  }\n  return { srcStat, destStat }\n}\n\n// recursively check if dest parent is a subdirectory of src.\n// It works for all file types including symlinks since it\n// checks the src and dest inodes. It starts from the deepest\n// parent and stops once it reaches the src parent or the root path.\nasync function checkParentPaths (src, srcStat, dest, funcName) {\n  const srcParent = path.resolve(path.dirname(src))\n  const destParent = path.resolve(path.dirname(dest))\n  if (destParent === srcParent || destParent === path.parse(destParent).root) return\n\n  let destStat\n  try {\n    destStat = await fs.stat(destParent, { bigint: true })\n  } catch (err) {\n    if (err.code === 'ENOENT') return\n    throw err\n  }\n\n  if (areIdentical(srcStat, destStat)) {\n    throw new Error(errMsg(src, dest, funcName))\n  }\n\n  return checkParentPaths(src, srcStat, destParent, funcName)\n}\n\nfunction checkParentPathsSync (src, srcStat, dest, funcName) {\n  const srcParent = path.resolve(path.dirname(src))\n  const destParent = path.resolve(path.dirname(dest))\n  if (destParent === srcParent || destParent === path.parse(destParent).root) return\n  let destStat\n  try {\n    destStat = fs.statSync(destParent, { bigint: true })\n  } catch (err) {\n    if (err.code === 'ENOENT') return\n    throw err\n  }\n  if (areIdentical(srcStat, destStat)) {\n    throw new Error(errMsg(src, dest, funcName))\n  }\n  return checkParentPathsSync(src, srcStat, destParent, funcName)\n}\n\nfunction areIdentical (srcStat, destStat) {\n  // stat.dev can be 0n on windows when node version >= 22.x.x\n  return destStat.ino !== undefined && destStat.dev !== undefined && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev\n}\n\n// return true if dest is a subdir of src, otherwise false.\n// It only checks the path strings.\nfunction isSrcSubdir (src, dest) {\n  const srcArr = path.resolve(src).split(path.sep).filter(i => i)\n  const destArr = path.resolve(dest).split(path.sep).filter(i => i)\n  return srcArr.every((cur, i) => destArr[i] === cur)\n}\n\nfunction errMsg (src, dest, funcName) {\n  return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`\n}\n\nmodule.exports = {\n  // checkPaths\n  checkPaths: u(checkPaths),\n  checkPathsSync,\n  // checkParent\n  checkParentPaths: u(checkParentPaths),\n  checkParentPathsSync,\n  // Misc\n  isSrcSubdir,\n  areIdentical\n}\n"
  },
  {
    "path": "lib/util/utimes.js",
    "content": "'use strict'\n\nconst fs = require('../fs')\nconst u = require('universalify').fromPromise\n\nasync function utimesMillis (path, atime, mtime) {\n  // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)\n  const fd = await fs.open(path, 'r+')\n\n  let closeErr = null\n\n  try {\n    await fs.futimes(fd, atime, mtime)\n  } finally {\n    try {\n      await fs.close(fd)\n    } catch (e) {\n      closeErr = e\n    }\n  }\n\n  if (closeErr) {\n    throw closeErr\n  }\n}\n\nfunction utimesMillisSync (path, atime, mtime) {\n  const fd = fs.openSync(path, 'r+')\n  fs.futimesSync(fd, atime, mtime)\n  return fs.closeSync(fd)\n}\n\nmodule.exports = {\n  utimesMillis: u(utimesMillis),\n  utimesMillisSync\n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"fs-extra\",\n  \"version\": \"11.3.4\",\n  \"description\": \"fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.\",\n  \"engines\": {\n    \"node\": \">=14.14\"\n  },\n  \"homepage\": \"https://github.com/jprichardson/node-fs-extra\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/jprichardson/node-fs-extra.git\"\n  },\n  \"keywords\": [\n    \"fs\",\n    \"file\",\n    \"file system\",\n    \"copy\",\n    \"directory\",\n    \"extra\",\n    \"mkdirp\",\n    \"mkdir\",\n    \"mkdirs\",\n    \"recursive\",\n    \"json\",\n    \"read\",\n    \"write\",\n    \"extra\",\n    \"delete\",\n    \"remove\",\n    \"touch\",\n    \"create\",\n    \"text\",\n    \"output\",\n    \"move\",\n    \"promise\"\n  ],\n  \"author\": \"JP Richardson <jprichardson@gmail.com>\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"graceful-fs\": \"^4.2.0\",\n    \"jsonfile\": \"^6.0.1\",\n    \"universalify\": \"^2.0.0\"\n  },\n  \"devDependencies\": {\n    \"klaw\": \"^2.1.1\",\n    \"klaw-sync\": \"^3.0.2\",\n    \"minimist\": \"^1.1.1\",\n    \"mocha\": \"^10.1.0\",\n    \"nyc\": \"^15.0.0\",\n    \"proxyquire\": \"^2.0.1\",\n    \"read-dir-files\": \"^0.1.1\",\n    \"standard\": \"^17.0.0\"\n  },\n  \"main\": \"./lib/index.js\",\n  \"exports\": {\n    \".\": \"./lib/index.js\",\n    \"./esm\": \"./lib/esm.mjs\"\n  },\n  \"files\": [\n    \"lib/\",\n    \"!lib/**/__tests__/\"\n  ],\n  \"scripts\": {\n    \"lint\": \"standard\",\n    \"test-find\": \"find ./lib/**/__tests__ -name *.test.js | xargs mocha\",\n    \"test\": \"npm run lint && npm run unit && npm run unit-esm\",\n    \"unit\": \"nyc node test.js\",\n    \"unit-esm\": \"node test.mjs\"\n  },\n  \"sideEffects\": false\n}\n"
  },
  {
    "path": "test/readme.md",
    "content": "Looking for the test files? You can find all of the test files in `lib/**/__tests__`."
  },
  {
    "path": "test.js",
    "content": "'use strict'\n\nconst os = require('os')\nconst path = require('path')\nconst klaw = require('klaw')\nconst Mocha = require('mocha')\n\nconst argv = require('minimist')(process.argv.slice(2))\n\nconst mochaOpts = {\n  ui: 'bdd',\n  reporter: 'dot',\n  timeout: 30000,\n  ...argv\n}\n\nconst mocha = new Mocha(mochaOpts)\nconst testExt = '.test.js'\n\nklaw('./lib').on('readable', function () {\n  let item\n  while ((item = this.read())) {\n    if (!item.stats.isFile()) return\n    if (item.path.lastIndexOf(testExt) !== (item.path.length - testExt.length)) return\n    mocha.addFile(item.path)\n  }\n}).on('end', () => {\n  mocha.run(failures => {\n    require('./lib').remove(path.join(os.tmpdir(), 'fs-extra'), () => process.exit(failures))\n  })\n})\n"
  },
  {
    "path": "test.mjs",
    "content": "import assert from 'assert'\nimport fsLegacy from './lib/index.js'\n// NOTE: eslint comments needed because we're importing the same file multiple times\nimport fsDefault from './lib/esm.mjs' // eslint-disable-line\nimport * as fsStar from './lib/esm.mjs'\nimport {\n  copy,\n  copySync,\n  emptyDirSync,\n  emptydirSync,\n  emptyDir,\n  emptydir,\n  createFile,\n  createFileSync,\n  ensureFile,\n  ensureFileSync,\n  createLink,\n  createLinkSync,\n  ensureLink,\n  ensureLinkSync,\n  createSymlink,\n  createSymlinkSync,\n  ensureSymlink,\n  ensureSymlinkSync,\n  readJson,\n  readJsonSync,\n  writeJson,\n  writeJsonSync,\n  outputJson,\n  outputJsonSync,\n  outputJSON,\n  outputJSONSync,\n  writeJSON,\n  writeJSONSync,\n  readJSON,\n  readJSONSync,\n  mkdirs,\n  mkdirsSync,\n  mkdirp,\n  mkdirpSync,\n  ensureDir,\n  ensureDirSync,\n  move,\n  moveSync,\n  outputFile,\n  outputFileSync,\n  pathExists,\n  pathExistsSync,\n  remove,\n  removeSync\n} from './lib/esm.mjs' // eslint-disable-line\nconst fsNamed = [\n  copy,\n  copySync,\n  emptyDirSync,\n  emptydirSync,\n  emptyDir,\n  emptydir,\n  createFile,\n  createFileSync,\n  ensureFile,\n  ensureFileSync,\n  createLink,\n  createLinkSync,\n  ensureLink,\n  ensureLinkSync,\n  createSymlink,\n  createSymlinkSync,\n  ensureSymlink,\n  ensureSymlinkSync,\n  readJson,\n  readJsonSync,\n  writeJson,\n  writeJsonSync,\n  outputJson,\n  outputJsonSync,\n  outputJSON,\n  outputJSONSync,\n  writeJSON,\n  writeJSONSync,\n  readJSON,\n  readJSONSync,\n  mkdirs,\n  mkdirsSync,\n  mkdirp,\n  mkdirpSync,\n  ensureDir,\n  ensureDirSync,\n  move,\n  moveSync,\n  outputFile,\n  outputFileSync,\n  pathExists,\n  pathExistsSync,\n  remove,\n  removeSync\n]\n\nconst keys = Object.keys(fsDefault)\n\nassert.deepStrictEqual(Object.values(fsDefault), fsNamed, 'named and default exports should match')\nassert.deepStrictEqual(\n  Object.entries(fsStar)\n    .filter(([name]) => name !== 'default') // remove \"default\" property here\n    .sort(([nameA], [nameB]) => keys.indexOf(nameA) - keys.indexOf(nameB)) // sort for exact match\n    .map(([name, fn]) => fn),\n  Object.values(fsDefault),\n  'star and default exports should match'\n)\n\n// default exports a subset of the legacy implementation, but functions are the same\nObject.entries(fsDefault).forEach(([name, fn]) => {\n  assert.strictEqual(fn, fsLegacy[name], `${name}() should match legacy implementation`)\n})\n\nconsole.warn('ESM tests pass!')\n"
  }
]