From 9f4e6c36a1eb519ef53bc099c2211460642555da Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Wed, 29 Jul 2026 20:30:58 +0200 Subject: [PATCH] feat(build): add file accessing utility --- build/utils/fileAccess.js | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 build/utils/fileAccess.js diff --git a/build/utils/fileAccess.js b/build/utils/fileAccess.js new file mode 100644 index 0000000..9cbb439 --- /dev/null +++ b/build/utils/fileAccess.js @@ -0,0 +1,47 @@ +/* +Copyright 2026 Seekra + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { access, constants, stat } from 'node:fs/promises'; + +export const checkFileReadAccess = async function checkFileWriteAccess (path) { + try { + await access(path, constants.F_OK | constants.R_OK); + return true; + } catch (err) { + if (err.code === 'ENOENT' || err.code === 'EACCES') return false; + else throw err; + } +}; + +export const exists = async function exists (path) { + try { + await access(path, constants.F_OK); + return true; + } catch (err) { + if (err.code === 'ENOENT') return false; + else throw err; + } +}; + +export const isDirectory = async function isDirectory (path) { + try { + const stats = await stat(path); + return stats.isDirectory(); + } catch (err) { + if (err.code === 'ENOENT' || err.code === 'EACCES') return false; + else throw err; + } +}; \ No newline at end of file