MCPcopy
hub / github.com/Fission-AI/OpenSpec / canWriteFile

Method canWriteFile

src/utils/file-system.ts:185–216  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

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 {

Callers 12

acquireFileLockFunction · 0.80
configureProfileMethod · 0.80
removeProfileConfigMethod · 0.80
installMethod · 0.80
uninstallMethod · 0.80
installMethod · 0.80
uninstallMethod · 0.80
configureBashrcMethod · 0.80
installMethod · 0.80
configureZshrcMethod · 0.80
installMethod · 0.80

Calls 2

hasWritableModeAndAccessFunction · 0.85

Tested by

no test coverage detected