Skip to content

Commit

Permalink
Add: check if DestDir and InterDir are on the same disk
Browse files Browse the repository at this point in the history
  • Loading branch information
dnzbk committed Aug 29, 2024
1 parent 864d527 commit f29cb17
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
12 changes: 10 additions & 2 deletions webui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,21 @@ <h4>System</h4>
<td id="SysInfo_Arch" width="50%"></td>
</tr>
<tr>
<td width="50%">Free disk space</td>
<td width="50%">Free disk space (DestDir)</td>
<td id="SysInfo_FreeDiskSpace" width="50%"></td>
</tr>
<tr>
<td width="50%">Total disk space</td>
<td width="50%">Total disk space (DestDir)</td>
<td id="SysInfo_TotalDiskSpace" width="50%"></td>
</tr>
<tr id="SysInfo_FreeInterDiskSpaceTr">
<td width="50%">Free disk space (InterDir)</td>
<td id="SysInfo_FreeInterDiskSpace" width="50%"></td>
</tr>
<tr id="SysInfo_TotalInterDiskSpaceTr">
<td width="50%">Total disk space (InterDir)</td>
<td id="SysInfo_TotalInterDiskSpace" width="50%"></td>
</tr>
<tr>
<td width="50%">Write buffer</td>
<td id="SysInfo_WriteBuffer" width="50%"></td>
Expand Down
42 changes: 42 additions & 0 deletions webui/system-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var SystemInfo = (new function($)
var $SysInfo_IP;
var $SysInfo_FreeDiskSpace;
var $SysInfo_TotalDiskSpace;
var $SysInfo_FreeInterDiskSpace;
var $SysInfo_TotalInterDiskSpace;
var $SysInfo_FreeInterDiskSpaceTr;
var $SysInfo_TotalInterDiskSpaceTr;
var $SysInfo_ArticleCache;
var $SysInfo_WriteBuffer;
var $SysInfo_ToolsTable;
Expand Down Expand Up @@ -65,7 +69,23 @@ var SystemInfo = (new function($)
update: function(status)
{
$SysInfo_Uptime.text(Util.formatTimeHMS(status['UpTimeSec']));

var destDirOpt = Options.findOption(Options.options, 'DestDir');
var interDirOpt = Options.findOption(Options.options, 'InterDir');

renderDiskSpace(+status['FreeDiskSpaceMB'], +status['TotalDiskSpaceMB']);

if (destDirOpt && interDirOpt && !pathsOnSameDisk(destDirOpt.Value, interDirOpt.Value))
{
$SysInfo_FreeInterDiskSpaceTr.show();
$SysInfo_TotalInterDiskSpaceTr.show();
renderInterDiskSpace(+status['FreeInterDiskSpaceMB'], +status['TotalInterDiskSpaceMB']);
}
else
{
$SysInfo_FreeInterDiskSpaceTr.hide();
$SysInfo_TotalInterDiskSpaceTr.hide();
}
}
}

Expand Down Expand Up @@ -98,6 +118,10 @@ var SystemInfo = (new function($)
$SysInfo_IP = $('#SysInfo_IP');
$SysInfo_FreeDiskSpace = $('#SysInfo_FreeDiskSpace');
$SysInfo_TotalDiskSpace = $('#SysInfo_TotalDiskSpace');
$SysInfo_FreeInterDiskSpace = $('#SysInfo_FreeInterDiskSpace');
$SysInfo_TotalInterDiskSpace = $('#SysInfo_TotalInterDiskSpace');
$SysInfo_FreeInterDiskSpaceTr = $('#SysInfo_FreeInterDiskSpaceTr');
$SysInfo_TotalInterDiskSpaceTr = $('#SysInfo_TotalInterDiskSpaceTr');
$SysInfo_ArticleCache = $('#SysInfo_ArticleCache');
$SysInfo_WriteBuffer = $('#SysInfo_WriteBuffer');
$SysInfo_ToolsTable = $('#SysInfo_ToolsTable');
Expand Down Expand Up @@ -136,6 +160,17 @@ var SystemInfo = (new function($)
);
}

function pathsOnSameDisk(path1, path2)
{
path1 = path1.replace(/\\/g, '/');
path2 = path2.replace(/\\/g, '/');

var drive1 = path1.match(/^[a-zA-Z]:\//i) ? path1.match(/^[a-zA-Z]:\//i)[0] : '/';
var drive2 = path2.match(/^[a-zA-Z]:\//i) ? path2.match(/^[a-zA-Z]:\//i)[0] : '/';

return drive1 === drive2;
}

function hideSpinner()
{
$SystemInfo_Spinner.hide();
Expand Down Expand Up @@ -264,6 +299,13 @@ var SystemInfo = (new function($)
$SysInfo_TotalDiskSpace.text(Util.formatSizeMB(total));
}

function renderInterDiskSpace(free, total)
{
var percents = total !== 0 ? (free / total * 100).toFixed(1) + '%' : '0.0%';
$SysInfo_FreeInterDiskSpace.text(Util.formatSizeMB(free) + ' / ' + percents);
$SysInfo_TotalInterDiskSpace.text(Util.formatSizeMB(total));
}

function renderIP(network)
{
var privateIP = network.PrivateIP ? network.PrivateIP : 'N/A';
Expand Down

0 comments on commit f29cb17

Please sign in to comment.