I have an script that does this:
rm -rf "$test_dir" && sync && mkdir -p "$test_dir"
unzip -qq "$zip" -d "$test_dir"
# compile and run some stuff, diff some files...
evince "$pdf" 2>/dev/null # $pdf is a path inside the mentioned folder $test_dir
echo "[Next]..."
read
# then it goes to the next zip, and do the same again.
- Let's call a zip file
A.zip
, and the next (in the list of zip files)B.zip
. - Each zip file comes with two text files, and a pdf.
The problem:
When the extraction folder was already deleted, and re-created, and it is the turn of B.zip, I cat a text file, and open the pdf in evince. Evince shows the correct pdf from B.zip
for one or two seconds.
After that, evince reloads the document, and shows the pdf that came from A.zip
.
If I go and manually open the pdf again, it is effectively the one that came in A.zip
instead of the one in B.zip
(so evince is just opening the new file).
If I manually cat the text file again, the content is not the one of the last cat registered in the terminal (the one in B.zip
), but the content of the text file of A.zip
Suspicions:
I am suspecting that somehow, the folder itself (or its content) is coming back from deletion.
Fix attempts:
Previously, I deleted the content of "$test_dir", but not the directory itself. The problem showed very often. Then I decided to delete the folder and re-mkdir
it. This seemed to solve it. But now I am seeing the problem again.
I tried adding a sync
command right after rm -rf
so that goes into disk. The problem persists.
I tried sleep
for a second after deletion. The problem persists.
What I have checked:
I have seen several similar questions on the web, but all of them involve some other process, docker, or something else. The folder I am using is just a directory in my home. There is no process running anything special on it, except my script ([update] there was one actually, please see the answer)
I have checked, and I am not unzipping anything anywhere else in the script.
答案1
I found the responsible! it is the MegaSync application. It is running in the background, and somehow, while syncing all, it brings back the just deleted files. I close it, and problem solved.