Skip to content

Commit

Permalink
fix(TridentFileSystem): skip file creation if it already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
yuiseki committed Nov 7, 2024
1 parent 76bb549 commit 3fa811e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/app/charites/TridentFileSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ export const TridentFileSystem: React.FC = () => {
const dirHandle = dirPath
? await rootDir.getDirectoryHandle(dirPath)
: rootDir;
// ファイルを作成
const fileName = pathParts[pathParts.length - 1];
const fileHandle = await dirHandle.getFileHandle(fileName, {
create: true,
});
const writable = await fileHandle.createWritable();
await writable.write(content);
await writable.close();
// ファイルが存在する場合はスキップ
try {
await dirHandle.getFileHandle(pathParts[pathParts.length - 1]);
continue;
} catch (error) {
// ファイルが存在しない場合は作成
const fileName = pathParts[pathParts.length - 1];
const fileHandle = await dirHandle.getFileHandle(fileName, {
create: true,
});
const writable = await fileHandle.createWritable();
await writable.write(content);
await writable.close();
}
}

// style.yml ファイルを作成または取得
Expand Down

0 comments on commit 3fa811e

Please sign in to comment.