TeeJee.FileSystem.file_write() uses non-atomic delete + create, risking File exists collisions on rsync-log-changes

Aperta
#584 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Ambito
backend

Direzione di ricerca

Start with file_write() in src/Utility/TeeJee.FileSystem.vala (around lines 165-185) and the finish_called flag in src/Utility/AsyncTask.vala (around lines 295-298), then check the callers RsyncTask.finish_task() and RsyncTask.parse_log(). Confirm whether replacing the delete-then-create sequence with an atomic replace preserves the current behaviour for existing callers. Done means both spots are hardened without changing results, which needs confirmation from a maintainer since the issue is a proposal rather than a reproduced bug.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

While investigating Error opening file ".../rsync-log-changes": File exists during fast rsync snapshot runs on Timeshift 25.12.4, I found that the primary trigger was the dual-thread finish() race fixed in #552 (c112e86).

However, inspecting src/Utility/TeeJee.FileSystem.vala and src/Utility/AsyncTask.vala after #552 shows two remaining defensive edge cases that could still allow File exists errors or non-atomic writes if file_write() or finish() is ever invoked concurrently:

1. Non-atomic file_write() (src/Utility/TeeJee.FileSystem.vala:165-185)

Currently, file_write() performs a separate existence check, delete, and FileCreateFlags.NONE creation:

var file = File.new_for_path (file_path);
if (file.query_exists ()) {
	file.delete ();
}

var file_stream = file.create (FileCreateFlags.NONE);

If two callers (such as RsyncTask.finish_task() and RsyncTask.parse_log()) ever target the same path concurrently—or if a snapshot is interrupted mid-write—this TOCTOU sequence can fail with File exists or leave a truncated rsync-log-changes file.

Using file.replace(null, false, FileCreateFlags.REPLACE_DESTINATION) (or File.replace_contents()) would make file_write() atomic and eliminate File exists collisions across all callers.

2. Non-atomic finish_called guard (src/Utility/AsyncTask.vala:295-298)

#552 cleanly serializes finish() via wait_and_finish(), so there is currently only one caller. Hardening finish_called with GLib.AtomicInt (e.g., AtomicInt.compare_and_exchange(ref finish_called, 0, 1)) would ensure finish() remains thread-safe if any subclass or future change ever calls it directly.

Environment
  • Timeshift 25.12.4 (Linux Mint 22.3) running on an older Apple iMac
  • An external FireWire drive is the snapshot target where rsync completes in ~35s if no major changes have been made
Lingua principale
Vala
Stelle
4.3k
Fork
162
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di linuxmint/timeshift

Tutte le issue di linuxmint/timeshift

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.