Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions monitor-dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,20 @@ echo "使用文件监控工具: $watcher"

if [ "$watcher" = "inotifywait" ]; then
# Linux/Unix 系统使用 inotifywait
inotifywait --exclude '(.tmp)' -r -m --format '%w%f %e' -e moved_to "$@" | while IFS= read -r line; do
inotifywait --exclude '(.tmp)' -r -m --format '%w%f %e' -e moved_to,create "$@" | while IFS= read -r line; do
echo "原始事件: $line"
# 检查是否包含 ISDIR
if [[ "$line" == *"ISDIR"* ]]; then

# 检查是否是目录事件(创建或移动)
if [[ "$line" == *"CREATE,ISDIR"* ]] || [[ "$line" == *"MOVED_TO,ISDIR"* ]]; then
# 使用更安全的方式解析路径和事件
# 找到最后一个空格的位置,分离路径和事件
event_part="${line##* }"
path_part="${line% *}"

echo "检测到目录移动事件: $path_part"
if [[ "$line" == *"CREATE,ISDIR"* ]]; then
Comment on lines +104 to +109
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current string match assumes a fixed event order (CREATE,ISDIR or MOVED_TO,ISDIR). It would be more robust to split event_part on commas and check for the presence of CREATE/MOVED_TO and ISDIR independently, handling any order or additional flags.

Copilot uses AI. Check for mistakes.
echo "检测到目录创建事件: $path_part"
else
echo "检测到目录移动事件: $path_part"
fi
echo "事件类型: $event_part"

# 等待目录稳定后再处理
Expand All @@ -122,19 +126,16 @@ elif [ "$watcher" = "fswatch" ]; then
fswatch -r "$@" | while IFS= read -r changed_path; do
echo "检测到变化: $changed_path"

# 检查是否是新创建的目录
# 检查是否是目录
if [ -d "$changed_path" ]; then
# 检查目录是否是新移动过来的(简单的启发式检查)
if [ -n "$(find "$changed_path" -mindepth 1 -maxdepth 1 2>/dev/null)" ]; then
echo "检测到新目录: $changed_path"
echo "检测到目录事件: $changed_path"

# 等待目录稳定后再处理
wait_for_directory_stable "$changed_path"
# 等待目录稳定后再处理
wait_for_directory_stable "$changed_path"

# 处理目录
echo "开始处理目录: $changed_path"
"${BIN_PATH}/file-clean-rust" --prune "$changed_path"
fi
# 处理目录
echo "开始处理目录: $changed_path"
"${BIN_PATH}/file-clean-rust" --prune "$changed_path"
fi
done
fi