From c21aecab056ffb9b900ed9caf7048b093059e877 Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Thu, 7 May 2026 21:20:13 +0300 Subject: [PATCH 1/8] Enhance comments for partition directory setup Added comments to clarify partition directory configuration options. --- plugins/diskspace/conf.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/diskspace/conf.php b/plugins/diskspace/conf.php index 1e0b36e81..1a7d45c06 100644 --- a/plugins/diskspace/conf.php +++ b/plugins/diskspace/conf.php @@ -4,4 +4,18 @@ $notifySpaceLimit = 512; // in Mb $partitionDirectory = null; // if null, then we will check rtorrent download directory (or $topDirectory if rtorrent is unavailable) // otherwise, set this to the absolute path for checked partition. +// To have multiple mountpoint checks add them in array like this +//$partitionDirectory = [ +// '/mnt/disk1', +// '/mnt/disk2', +// '/mnt/disk3' +//]; +// +//or like this +// +//$partitionDirectory = array( +// '/mnt/disk1', +// '/mnt/disk2', +// '/mnt/disk3' +//); $freeBytesInMeter = false; // show free space instead of % From db57ea745e728768b1564564bb8adb32d9916548 Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Thu, 7 May 2026 21:26:54 +0300 Subject: [PATCH 2/8] Refactor disk space handling for partition directory --- plugins/diskspace/action.php | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/plugins/diskspace/action.php b/plugins/diskspace/action.php index 23922e338..b8e25b1a1 100644 --- a/plugins/diskspace/action.php +++ b/plugins/diskspace/action.php @@ -1,28 +1,45 @@ linkExist && file_exists(rTorrentSettings::get()->directory) ) { - $partitionDirectory = rTorrentSettings::get()->directory; // Then we can show the disk space of the download directory + $partitionDirectory = array( rTorrentSettings::get()->directory ); // Then we can show the disk space of the download directory } else { - $partitionDirectory = &$topDirectory; // Else, we show $topDirectory by default as fallback + $partitionDirectory = array( $topDirectory); // Else, we show $topDirectory by default as fallback } } - $ret = array - ( + elseif( !is_array($partitionDirectory) ) + { + $partitionDirectory = array($partitionDirectory); + } + + $diskSpace = rDiskSpace::load($partitionDirectory); + + $current = $diskSpace->updateOldest(); + + $ret = array( "total" => 0, - "free" => 0 + "free" => 0, + "path" => "", + "updated" => 0, + "all" => array() ); - if( is_dir($partitionDirectory) ) + + if( $current ) { - $ret["total"] = disk_total_space($partitionDirectory); - $ret["free"] = disk_free_space($partitionDirectory); + $ret["total"] = $current["total"]; + $ret["free"] = $current["free"]; + $ret["path"] = $current["path"]; + $ret["updated"] = $current["updated"]; } + + $ret["all"] = $diskSpace->getAll(); CachedEcho::send(JSON::safeEncode($ret),"application/json"); From fae0f51b7921234965f15f1cd5a356cd4724bc5d Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Thu, 7 May 2026 21:27:58 +0300 Subject: [PATCH 3/8] Add rDiskSpace class for disk space management --- plugins/diskspace/disk.php | 147 +++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 plugins/diskspace/disk.php diff --git a/plugins/diskspace/disk.php b/plugins/diskspace/disk.php new file mode 100644 index 000000000..9ce68f6c7 --- /dev/null +++ b/plugins/diskspace/disk.php @@ -0,0 +1,147 @@ +get($obj) ) + { + $obj->initialize($paths); + $obj->store(); + } + else + { + $obj->sync($paths); + } + + return $obj; + } + + public function initialize( $paths ) + { + $this->disks = array(); + + foreach( $paths as $path ) + { + $this->disks[] = array( + 'path' => $path, + 'total' => 0, + 'free' => 0, + 'updated' => 0 + ); + } + } + + public function sync( $paths ) + { + $current = array(); + + foreach( $this->disks as $disk ) + $current[$disk['path']] = $disk; + + $newDisks = array(); + + foreach( $paths as $path ) + { + if( isset($current[$path]) ) + $newDisks[] = $current[$path]; + else + { + $newDisks[] = array( + 'path' => $path, + 'total' => 0, + 'free' => 0, + 'updated' => 0 + ); + } + } + + $this->disks = $newDisks; + $this->store(); + } + + public function store() + { + $cache = new rCache(); + return $cache->set($this); + } + + public function getOldestIndex() + { + $oldestIndex = 0; + $oldestTime = PHP_INT_MAX; + + foreach( $this->disks as $index => $disk ) + { + if( $disk['updated'] < $oldestTime ) + { + $oldestTime = $disk['updated']; + $oldestIndex = $index; + } + } + + return $oldestIndex; + } + + public function updateOldest() + { + if( empty($this->disks) ) + return null; + + $index = $this->getOldestIndex(); + + $path = $this->disks[$index]['path']; + + if( is_dir($path) ) + { + $this->disks[$index]['total'] = intval(@disk_total_space($path)); + $this->disks[$index]['free'] = intval(@disk_free_space($path)); + } + else + { + $this->disks[$index]['total'] = 0; + $this->disks[$index]['free'] = 0; + } + + $this->disks[$index]['updated'] = time(); + + $this->store(); + + return $this->disks[$index]; + } + + public function getNewest() + { + if( empty($this->disks) ) + return null; + + $newest = null; + $newestTime = 0; + + foreach( $this->disks as $disk ) + { + if( $disk['updated'] >= $newestTime ) + { + $newestTime = $disk['updated']; + $newest = $disk; + } + } + + return $newest; + } + + public function getAll() + { + return $this->disks; + } +} From f8a076cafb74ff16a74e31375dc47332246a2ba6 Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Thu, 7 May 2026 21:32:01 +0300 Subject: [PATCH 4/8] Enhance disk usage tooltip with detailed info --- plugins/diskspace/init.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/plugins/diskspace/init.js b/plugins/diskspace/init.js index 011c65752..10f88aebc 100644 --- a/plugins/diskspace/init.js +++ b/plugins/diskspace/init.js @@ -11,12 +11,33 @@ plugin.setValue = function( full, free ) visibility: !percent ? "hidden" : "visible" } ); if(plugin.freeBytesInMeter) $("#meter-disk-text").text(theConverter.bytes(free)); else $("#meter-disk-text").text(percent+'%'); - $("#meter-disk-pane").prop("title", - theUILang.diskUsage - .replace(/%USED%/, theConverter.bytes(used)) - .replace(/%TOTAL%/, theConverter.bytes(full)) - .replace(/%FREE%/, theConverter.bytes(free)) - ); + var tooltip = []; + if(all && all.length) + { + for(var i = 0; i < all.length; i++) + { + var disk = all[i]; + var dUsed = disk.total - disk.free; + var dPercent = disk.total ? Math.round(dUsed / disk.total * 100) : 0; + tooltip.push( + disk.path + "\n" + + theUILang.diskUsage + .replace(/%USED%/, theConverter.bytes(dUsed)) + .replace(/%TOTAL%/, theConverter.bytes(disk.total)) + .replace(/%FREE%/, theConverter.bytes(disk.free)) + ); + } + } + else + { + tooltip.push( + theUILang.diskUsage + .replace(/%USED%/, theConverter.bytes(used)) + .replace(/%TOTAL%/, theConverter.bytes(full)) + .replace(/%FREE%/, theConverter.bytes(free)) + ); + } + $("#meter-disk-pane").prop("title", tooltip.join("\n------------------\n")); if($.noty && plugin.allStuffLoaded) { From 846d180a00e50b904aafe306e4e5f79366cb38c2 Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Thu, 7 May 2026 21:35:07 +0300 Subject: [PATCH 5/8] Fix variable reference for disk space checks --- plugins/diskspace/init.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/diskspace/init.php b/plugins/diskspace/init.php index 4022e0538..5ad78d4bb 100644 --- a/plugins/diskspace/init.php +++ b/plugins/diskspace/init.php @@ -14,9 +14,12 @@ $partitionDirectory = &$topDirectory; // Else, we show $topDirectory by default as fallback } } +$checkDirectory = $partitionDirectory; +if (is_array($partitionDirectory)) + $checkDirectory = reset($partitionDirectory); if(!function_exists('disk_total_space') || !function_exists('disk_free_space') || - (disk_total_space($partitionDirectory)===false) || (disk_free_space($partitionDirectory)===false)) + (disk_total_space(checkDirectory)===false) || (disk_free_space(checkDirectory)===false)) $jResult .= "plugin.disable();"; else { From 21e3cff2f3b05ef3ba14ebd5956bf9450cfc73c9 Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Fri, 8 May 2026 09:16:57 +0300 Subject: [PATCH 6/8] Add 'all' parameter to setValue function --- plugins/diskspace/init.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/diskspace/init.js b/plugins/diskspace/init.js index 10f88aebc..b19e5e8ac 100644 --- a/plugins/diskspace/init.js +++ b/plugins/diskspace/init.js @@ -1,7 +1,7 @@ plugin.loadLang(); plugin.loadMainCSS(); -plugin.setValue = function( full, free ) +plugin.setValue = function( full, free, all ) { var used = full-free; var percent = iv(full ? used/full*100 : 0); @@ -89,7 +89,7 @@ plugin.init = function() cache: false, success : function(data) { - plugin.setValue( data.total, data.free ); + plugin.setValue( data.total, data.free, data.all ); }, complete : function(jqXHR, textStatus) { From 0f97df9a6405b6a294faca298e0924fa7417466d Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Fri, 8 May 2026 09:17:56 +0300 Subject: [PATCH 7/8] Change oldestTime initialization value --- plugins/diskspace/disk.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/diskspace/disk.php b/plugins/diskspace/disk.php index 9ce68f6c7..e78f72e06 100644 --- a/plugins/diskspace/disk.php +++ b/plugins/diskspace/disk.php @@ -79,7 +79,7 @@ public function store() public function getOldestIndex() { $oldestIndex = 0; - $oldestTime = PHP_INT_MAX; + $oldestTime = 9999999999; foreach( $this->disks as $index => $disk ) { From 0ea415b8225189fda9398b95af6ca680dbfef435 Mon Sep 17 00:00:00 2001 From: ranirahn <34799179+ranirahn@users.noreply.github.com> Date: Fri, 8 May 2026 09:23:16 +0300 Subject: [PATCH 8/8] Fix check for disk space functions and variable usage --- plugins/diskspace/init.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/diskspace/init.php b/plugins/diskspace/init.php index 5ad78d4bb..83d4491e5 100644 --- a/plugins/diskspace/init.php +++ b/plugins/diskspace/init.php @@ -19,8 +19,10 @@ $checkDirectory = reset($partitionDirectory); if(!function_exists('disk_total_space') || !function_exists('disk_free_space') || - (disk_total_space(checkDirectory)===false) || (disk_free_space(checkDirectory)===false)) + (disk_total_space($checkDirectory)===false) || (disk_free_space($checkDirectory)===false)) +{ $jResult .= "plugin.disable();"; +} else { $jResult.="plugin.interval = ".$diskUpdateInterval."; plugin.notifySpaceLimit = ".($notifySpaceLimit*1024*1024).";";