Skip to content

Commit 32df0a4

Browse files
committed
Ensure complete replacement of CSV file on each execution
1 parent 783b995 commit 32df0a4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

docker-entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,21 @@ echo "🎬 [CRON] Starting Trakt to Letterboxd Export at ${START_TIME} 🎬"
243243
echo "📊 Exporting your Trakt data with option '${EXPORT_OPTION}'..."
244244
echo "======================================================================"
245245
246+
# Make sure any existing CSV file is removed
247+
CSV_LOCATIONS=(
248+
"/app/copy/letterboxd_import.csv"
249+
"/app/copy/copy/letterboxd_import.csv"
250+
"/app/letterboxd_import.csv"
251+
"./copy/letterboxd_import.csv"
252+
)
253+
254+
for csv_path in "${CSV_LOCATIONS[@]}"; do
255+
if [ -f "$csv_path" ]; then
256+
echo "🗑️ Removing existing CSV file at: $csv_path"
257+
rm -f "$csv_path"
258+
fi
259+
done
260+
246261
# Run the export script and capture exit code
247262
/app/Export_Trakt_4_Letterboxd.sh ${EXPORT_OPTION} > /app/logs/cron_export_$(date '+%Y-%m-%d_%H-%M-%S').log 2>&1
248263
EXIT_CODE=$?

lib/main.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,29 @@ process_data() {
266266
if [ -f "$final_output_file" ]; then
267267
echo "🗑️ Removing existing Letterboxd import file: $final_output_file" | tee -a "${log}"
268268
rm -f "$final_output_file"
269+
270+
# Verify removal was successful
271+
if [ -f "$final_output_file" ]; then
272+
echo "❌ ERROR: Failed to remove existing CSV file. Trying with force option." | tee -a "${log}"
273+
rm -f "$final_output_file"
274+
sleep 1
275+
fi
269276
fi
270277

278+
# Also check alternative paths and remove any existing files
279+
local alt_paths=(
280+
"${SCRIPT_DIR}/copy/letterboxd_import.csv"
281+
"/app/copy/letterboxd_import.csv"
282+
"./copy/letterboxd_import.csv"
283+
)
284+
285+
for alt_path in "${alt_paths[@]}"; do
286+
if [ -f "$alt_path" ] && [ "$alt_path" != "$final_output_file" ]; then
287+
echo "🗑️ Removing CSV file at alternate location: $alt_path" | tee -a "${log}"
288+
rm -f "$alt_path"
289+
fi
290+
done
291+
271292
# Create empty CSV file with header
272293
echo "Title,Year,imdbID,tmdbID,WatchedDate,Rating10,Rewatch" > "${temp_dir}/movies_export.csv"
273294

0 commit comments

Comments
 (0)