Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
denven opened this issue Sep 3, 2023 · 5 comments
Closed

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

denven opened this issue Sep 3, 2023 · 5 comments
Labels

Comments

@denven
Copy link
Contributor

denven commented Sep 3, 2023

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).

  • 2023090221-2023090223 (3 hours)
  • 2023090300 (1 hour)
  • 2023090303-2023090304 (2 hours)

image

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
Copy link
Contributor Author

denven commented Sep 3, 2023

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
Copy link
Owner

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
Copy link
Contributor Author

denven commented Sep 9, 2023

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
Copy link
Owner

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

roleoroleo added a commit that referenced this issue Sep 20, 2023
Copy link

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.

@github-actions github-actions bot added the Stale label Mar 31, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants