From e7ca1d7742fc0759731482bf3d84722646f0b4cb Mon Sep 17 00:00:00 2001 From: hummypkg Date: Mon, 5 Oct 2015 14:51:09 +0000 Subject: [PATCH] improve rmdir_if_empty, 1.2.5 git-svn-id: file:///root/webif/svn/pkg/webif/trunk@2488 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 2 +- webif/lib/system.class | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CONTROL/control b/CONTROL/control index 852db84..aae87a3 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 1.2.4-9 +Version: 1.2.5 Architecture: mipsel Maintainer: af123@hummypkg.org.uk Depends: webif-channelicons(>=1.1.18),lighttpd(>=1.4.35-2),jim(>=0.76),jim-oo,jim-sqlite3(>=0.76),jim-cgi(>=0.7),jim-binary(>=0.76),service-control(>=2.1),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.0),hmt(>=2.0.7),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7) diff --git a/webif/lib/system.class b/webif/lib/system.class index 98d91ab..0267772 100644 --- a/webif/lib/system.class +++ b/webif/lib/system.class @@ -427,23 +427,36 @@ proc {system mkdir_p} {dir} { exec /mod/bin/busybox/mkdir -p $dir } -proc {system rmdir_if_empty} {dir {why 0}} { +proc {system dirblockers} {dir {permitted {".*"}}} { set fl {} foreach e [readdir -nocomplain $dir] { - if {$e eq "." || $e eq ".."} continue + if {$e in {. ..}} continue if {[file isdirectory "$dir/$e"]} { - if {!$why} { return 0 } lappend fl $e - } elseif {[string index $e 0] ne "."} { - if {!$why} { return 0 } + continue + } + set flag 1 + foreach p $permitted { + if {[string match -nocase $p $e]} { + set flag 0 + break + } + } + if {$flag} { lappend fl $e } } - if {!$why} { + return $fl +} + +proc {system rmdir_if_empty} {dir {permitted {".*"}}} { + set fl [system dirblockers $dir $permitted] + + if {![llength $fl]} { file delete -force $dir return 1 } - return $fl + return 0 } proc {system listening} {{mport 0}} {