Skip to content

Commit

Permalink
Changed to continue processing on error
Browse files Browse the repository at this point in the history
  • Loading branch information
khattori committed Oct 26, 2024
1 parent 3e85615 commit ce41ab9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/commands/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ export default class Rm extends Command {
if (!options.force) {
const result = await KeClient.get(this.conf, target)
if (result === null) {
throw new Error(`failed to remove: '${target}' is not found`)
this.warn(`failed to remove: '${target}' is not found`)
return
}

if (result.type_object === DIRECTORY_TYPE) {
throw new Error(`failed to remove: '${target}' is a directory`)
this.warn(`failed to remove: '${target}' is a directory`)
return
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/commands/rmdir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ export default class Rmdir extends Command {
const result = await KeClient.get(this.conf, targetDir)

if (result === null) {
throw new Error(`failed to remove directory: '${targetDir}' is not found`)
this.warn(`failed to remove directory: '${targetDir}' is not found`)
return
}

if (result.type_object !== DIRECTORY_TYPE) {
throw new Error(`failed to remove directory: '${targetDir}' is not a directory`)
this.warn(`failed to remove directory: '${targetDir}' is not a directory`)
return
}

// ディレクトリが空かどうかチェックする
const results = await KeClient.getAll(this.conf, `${targetDir}.children`)
if (results!.count > 0) {
throw new Error(`failed to remove directory: '${targetDir}' is not empty`)
this.warn(`failed to remove directory: '${targetDir}' is not empty`)
return
}

await KeClient.del(this.conf, targetDir)
Expand Down

0 comments on commit ce41ab9

Please sign in to comment.