roleoroleo / sonoff-hack

Custom firmware for Sonoff GK-200MP2B camera
GNU General Public License v3.0
200 stars 45 forks source link

ftppush.sh: uses rmdir but rmdir does not exist on S-CAM #139

Closed couriersud closed 1 month ago

couriersud commented 1 year ago

ftppush (master) currently fails to remove empty folders. It uses rmdir which does not exist in the firmware. Replacing rmdir with rm -rf works, but is more risky since rmdir would fail on non-empty folders.

darkxst commented 1 year ago

We could easily add rmdir to the busybox build.

However I dont know why that snippet is not just using find to delete empty folders, something like the commented out code find <path> -type d -empty -delete

Edit: rmdir is built its just missing the symlink busybox find doesnt include the -empty command, but something like this should work

From 9935c41fd2827279ee5f81a0d69905605e09f6fa Mon Sep 17 00:00:00 2001
From: Tim Lunn <tim@feathertop.org>
Date: Tue, 4 Apr 2023 23:12:57 +1000
Subject: [PATCH] fix rmdir

---
 src/busybox/install.busybox                     | 2 ++
 src/static/static/sonoff-hack/script/ftppush.sh | 5 +----
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/busybox/install.busybox b/src/busybox/install.busybox
index 4043b2d..5aadf1e 100755
--- a/src/busybox/install.busybox
+++ b/src/busybox/install.busybox
@@ -15,3 +15,5 @@ echo "#!/mnt/mmc/sonoff-hack/bin/busybox" > ../../build/sonoff-hack/usr/bin/wget
 chmod 0755 ../../build/sonoff-hack/usr/bin/wget
 echo "#!/mnt/mmc/sonoff-hack/bin/busybox" > ../../build/sonoff-hack/usr/bin/xargs
 chmod 0755 ../../build/sonoff-hack/usr/bin/xargs
+echo "#!/mnt/mmc/sonoff-hack/bin/busybox" > ../../build/sonoff-hack/usr/bin/rmdir
+chmod 0755 ../../build/sonoff-hack/usr/bin/rmdir
diff --git a/src/static/static/sonoff-hack/script/ftppush.sh b/src/static/static/sonoff-hack/script/ftppush.sh
index ddf4d2c..4a7c5f8 100755
--- a/src/static/static/sonoff-hack/script/ftppush.sh
+++ b/src/static/static/sonoff-hack/script/ftppush.sh
@@ -89,10 +89,7 @@ checkFiles ()
    #
    # Delete empty sub directories
    if [ ! -z "${FOLDER_TO_WATCH}" ]; then
-       for d in $(find "${FOLDER_TO_WATCH}/" -mindepth 1 -type d); do
-           #find "${FOLDER_TO_WATCH}/" -mindepth 1 -type d -empty -delete
-           [ -z "`find $d -type f`" ] && rmdir $d
-       done
+       find "${FOLDER_TO_WATCH}/" -mindepth 1 -depth -type d -exec rmdir --ignore-fail-on-non-empty {} \;
    fi
    #
    return 0
-- 
2.37.2
couriersud commented 1 year ago

Ok, thanks, will give it a try. Shouldn't this become a pull request?

darkxst commented 1 year ago

yes, but I hadnt tested it at all yet

couriersud commented 1 year ago

Once PR #141 is applied this issue can be closed.

github-actions[bot] commented 2 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.