diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..e44e769 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-23 - Broken sed pipeline causing data loss +**Learning:** The command `sed 's// /g'` is invalid because of an empty regex and causes `sed` to fail. When used in a pipeline like `cat | sed | tr`, if `sed` fails, the downstream `tr` receives nothing, resulting in empty content for all files. Additionally, `cat file | ...` is an inefficient pattern (useless use of cat). +**Action:** Replace `cat file | sed ... | tr ...` with direct redirection `tr ... < file`. Always verify pipeline components individually to ensure they don't fail silently with `2>/dev/null`. diff --git a/codepack.sh b/codepack.sh index 0d8ae2c..9929abe 100755 --- a/codepack.sh +++ b/codepack.sh @@ -851,7 +851,8 @@ extract_files_content() { # Read file content and clean invalid characters local content="" if [[ -r "$file" && -s "$file" ]]; then - content=$(cat "$file" 2>/dev/null | sed 's// /g' 2>/dev/null | tr -cd '\11\12\15\40-\176' 2>/dev/null || echo "") + # Optimization: Use input redirection instead of cat, and remove broken sed command + content=$(tr -cd '\11\12\15\40-\176' < "$file" 2>/dev/null || echo "") fi debug_log "Content length: ${#content}" >&2