diff mbox series

scripts/feeds: remove target/linux/feeds dir if no target

Message ID 20230420173552.489-1-prasunmaiti87@gmail.com
State New
Headers show
Series scripts/feeds: remove target/linux/feeds dir if no target | expand

Commit Message

Prasun Maiti April 20, 2023, 5:35 p.m. UTC
From: "Maiti, Prasun" <prasunmaiti87@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@gmail.com>
---
 scripts/feeds | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

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;