This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use fs.access instead of fs.open to avoid having to open and close fi…
…le-descriptors. NodeJS is deprecating the automatic closing of fileHandlers during garbage collection. This commit updates the codebase to explicitly close the fileHandlers instead of relying on the deprecated behaviour. Below is the message that is displayed when running obt prior to this commit: "DeprecationWarning: Closing a FileHandle object on garbage collection is deprecated. Please close FileHandle objects explicitly using FileHandle.prototype.close(). In the future, an error will be thrown if a file descriptor is closed during garbage collection."
- Loading branch information
1 parent
7894525
commit 3715752
Showing
10 changed files
with
44 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
'use strict'; | ||
|
||
const open = require('fs/promises').open; | ||
const { access } = require('fs/promises'); | ||
const { constants } = require('fs'); | ||
|
||
/** | ||
* Node.JS no longer has an fs.exists method. | ||
* Instead we use the fs.open method in read (`r`) mode. | ||
* fs.open will throw an error if the file does not exist. | ||
* Instead we use the fs.access method and check we can read the file. | ||
* fs.access will throw an error if the file does not exist. | ||
* @param {string} file file-system path to the file you are wanting to check exists or not | ||
* @returns {Promise.<boolean>} Whether the file exists | ||
*/ | ||
module.exports = function fileExists(file) { | ||
return open(file, 'r') | ||
.then(() => true) | ||
.catch(() => false); | ||
module.exports = async function fileExists(file) { | ||
try { | ||
await access(file, constants.R_OK); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters