[PATCH] scripts/feeds: remove target/linux/feeds dir if no target

Prasun Maiti prasunmaiti87 at gmail.com
Thu Apr 20 10:35:52 PDT 2023


From: "Maiti, Prasun" <prasunmaiti87 at gmail.com>

If we uninstall last target from target/linux/feeds/
then feeds dir will be empty.

So, feeds dir is not needed anymore.

Signed-off-by: Maiti, Prasun <prasunmaiti87 at gmail.com>
---
 scripts/feeds | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/scripts/feeds b/scripts/feeds
index aee73e793f..5fca78fc8d 100755
--- a/scripts/feeds
+++ b/scripts/feeds
@@ -497,6 +497,12 @@ sub is_core_src($) {
 	return 0;
 }
 
+sub is_dir_empty {
+	my $dir = shift;
+	opendir(my $dh, $dir);
+	return scalar(grep { $_ ne "." && $_ ne ".." } readdir($dh));
+}
+
 sub install_target {
 	my $feed = shift;
 	my $name = shift;
@@ -771,6 +777,10 @@ sub uninstall {
 			system("rm -f ./package/feeds/*/$name");
 			$uninstall = 1;
 		}
+		my $count = is_dir_empty("target/linux/feeds");
+		if (!$count) {
+			system("rm -rvf ./target/linux/feeds");
+		}
 	}
 	$uninstall and refresh_config();
 	return 0;
-- 
2.17.1




More information about the openwrt-devel mailing list