OCR4all / LAREX

A semi-automatic open-source tool for Layout Analysis and Region EXtraction on early printed books.
MIT License
179 stars 33 forks source link

Use XML files in savedir when loading annotations #251

Closed Witiko closed 3 years ago

Witiko commented 3 years ago

This change makes it possible not only to save updated XML files to a savedir, but also to load them back from the savedir when the page has been refreshed. This turns the savedir into an overlay read-write layer for the bookpath, which may be the prefered modus operandi if we'd like to keep the bookpath read-only, but also allow the users to change the annotations.

With more than one user, this change can produce race conditions, where a user may load an incomplete annotation from the savedir. Using advisory locking should solve this problem:

try (RandomAccessFile file = new RandomAccessFile(path, "rw");
      FileChannel channel = file.getChannel();
      FileLock lock = channel.lock()) {
    // write to the channel
}
maxnth commented 3 years ago

Excuse the late reply, I just now found time to look into the PR. The changes should vastly improve the workflow when using a savedir, thank you.

Witiko commented 3 years ago

@maxnth Thanks. However, as I mentioned, using savedir for both reading and writing will lead to race conditions. The race where two users load the same XML file, perform different changes, and then overwrite each other's changes is difficult to overcome, but we should at least lock the file when writing, so that you can never read or write a partially written XML file and corrupt the data.