(filePath: string)
| 183 | } |
| 184 | |
| 185 | static async canWriteFile(filePath: string): Promise<boolean> { |
| 186 | try { |
| 187 | const stats = await fs.stat(filePath); |
| 188 | |
| 189 | if (stats.isDirectory()) { |
| 190 | return hasWritableModeAndAccess(filePath); |
| 191 | } |
| 192 | |
| 193 | if (!stats.isFile()) { |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | return hasWritableModeAndAccess(filePath); |
| 198 | } catch (error: any) { |
| 199 | if (error.code === 'ENOENT') { |
| 200 | // File doesn't exist - find first existing parent directory and check its permissions |
| 201 | const parentDir = path.dirname(filePath); |
| 202 | const existingDir = await this.findFirstExistingDirectory(parentDir); |
| 203 | |
| 204 | if (existingDir === null) { |
| 205 | // No existing parent directory found (edge case) |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | // Check if the existing parent directory is writable. |
| 210 | return hasWritableModeAndAccess(existingDir); |
| 211 | } |
| 212 | |
| 213 | console.debug(`Unable to determine write permissions for ${filePath}: ${error.message}`); |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static async directoryExists(dirPath: string): Promise<boolean> { |
| 219 | try { |
no test coverage detected