-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When deleting the cache, unnecessary directories are also deleted. #75
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
diskcache.go
Outdated
dirs++ | ||
} | ||
} | ||
if dirs > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if dirs > 1 { | |
if dirs > 0 { |
じゃないのってなんでですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自分自身が存在するはずだからです。parentを os.ReadDir して、隣にディレクトリがないかを確認しています。
dirs := 0 | ||
for _, e := range entries { | ||
if e.IsDir() { | ||
dirs++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これしきい値上回ったらearly breakして良さそう?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! ac292c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dirs > 1 の部分は、parent ディレクトリ内に現在削除対象のディレクトリ以外にもディレクトリが存在するかどうかを確認するための条件です。具体的な理由を説明すると以下の通りです。
このコードの目的は、削除対象のディレクトリ(dir)を、その上位の親ディレクトリに他のディレクトリが存在しない限り、再帰的に削除していくことです。
もし親ディレクトリ(parent)に複数のディレクトリが存在する場合(つまり dirs > 1)、削除対象のディレクトリ(dir)だけを削除します。これは、親ディレクトリには他の重要なディレクトリがまだ存在するため、親ディレクトリ自体を削除しないようにするためです。
一方で、親ディレクトリに削除対象以外のディレクトリがない場合(dirs == 1)、親ディレクトリ自体を再帰的に削除できるので、recursiveRemoveDir を使って上位のディレクトリまで削除を進めます。
簡単にまとめると、dirs > 1 は「親ディレクトリに複数のディレクトリが存在するかどうか」を確認しており、複数存在する場合にはその親ディレクトリを削除せず、対象のディレクトリだけを削除するための条件です。
This comment has been minimized.
This comment has been minimized.
cc80004
to
944e79b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Code Metrics Report
Details | | main (cb68696) | #75 (769c6b8) | +/- |
|--------------------|----------------|---------------|-------|
+ | Coverage | 76.6% | 77.8% | +1.1% |
| Files | 2 | 2 | 0 |
| Lines | 296 | 316 | +20 |
+ | Covered | 227 | 246 | +19 |
+ | Code to Test Ratio | 1:1.9 | 1:1.9 | +0.0 |
| Code | 617 | 647 | +30 |
+ | Test | 1192 | 1275 | +83 | Code coverage of files in pull request scope (76.0% → 77.5%)
Reported by octocov |
BenchmarkDiscCache1MBBody-4
Metadata
BenchmarkEncodeDecode1MBBody-4
Metadata
BenchmarkNGINXCache1MBBody-4
Metadata
Reported by octocov |
If directories are not deleted, the host's inodes will be exhausted.
NOTICE: This fix does not delete existing empty cache directories.