roleoroleo / yi-hack-MStar

Custom firmware for Yi 1080p camera based on MStar platform
GNU General Public License v3.0
830 stars 110 forks source link

v0.49 Directories are wrongly deleted by the auto cleaner #520

Closed denven closed 2 months ago

denven commented 10 months ago

I think this may rarely happen, but it happened to my device today,

I wrote a real-time uploader program to upload files to OneDrive, and I check video files from OneDrive when I am not home. It works for several months. Today I found that some video files are missing, I thought the camera ran into failure or something, but I can access the camera from Yi-Home official app. Then I supposed the uploader program may have some bug results in some upload failures.

I checked the uploader program logs when I returned home, my uploader program's last restart date was a long time ago, and it is working without reboot, so the camera never rebooted recently as well (each time the camera reboots, the uploader program will generate a new log). I checked the uploaded folders in OneDrive and the existing folders on my camera SD card. OneDrive already has some folders that are not shown on SD card (which were deleted by the yi-hack auto-cleaner), but some older directories on SD card are still there 2023Y09M01D05H, 2023Y09M01D10H. Video file folders between some time ranges are missing (not uploaded/may be wrongly deleted before being uploaded).

image

image

image

So the issue is that: yi-hack has some bug that it doesn't always clean files/directories from old to newer consecuitively, some newer files are deleted wrongly, and older files/directories are still kept.

the yi camera hack auto video cleaning configuration, I set the free space to 90% (which I originally took it as the threshold percentage to clean) image

denven commented 10 months ago

I guess the cleaner may not calculate and find the right folders to delete properly when the used SD card storage ratio is smaller.

Setting a smaller value like 10-50% is likely to avoid or reduce the risk of newer files/directories wrong deletion since each time it will clean only a smaller portion of the old files/folders from the existing folders.

roleoroleo commented 10 months ago

The script seems to be ok, it's very simple. Maybe there is another cleaning procedure inside the yi processes. I didn't check this case.

denven commented 10 months ago

I guess the cleaner may not calculate and find the right folders to delete properly when the used SD card storage ratio is smaller.

Setting a smaller value like 10-50% is likely to avoid or reduce the risk of newer files/directories wrong deletion since each time it will clean only a smaller portion of the old files/folders from the existing folders.

I checked the script clean_records.sh code, and it looks fine, however, it doesn't work properly for ls -lt to sort the folders by modification time. Otherwise, I cannot understand why the folder's modification time is changed and results in the wrong sort. I don't know if any other process that will change the record folder mtime.

image

image

I am not sure if it is a bug of the ls, but when removing the -t option, it will list and sort folders by name, I think it is okay to remove it since all the folders are named by yyyyYmmMddDhhH format, sort by folder name are equivalent to the sort by the folder created time from earlier to recent time under this circumstance.

image

image

Then the fix is to change the t to r: ls -lt | grep -v tmp | grep -v timelapse | tail -n1 | awk '{print $9}' to ls -lr | grep -v tmp | grep -v timelapse | tail -n1 | awk '{print $9}'

You can test it on your device to see whether you have the same situation as mine.

roleoroleo commented 9 months ago

I committed your changes to clean_records and to all other scripts.

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.