Skip to content

Commit

Permalink
Handle symlinked directories (#13)
Browse files Browse the repository at this point in the history
* Handle symlinked directories

In Trellis systems, the uploads directory is a symlink,
so we need to use realpath() to resolve the symlink
to ensure that we get an accurate directory size.

* Use escapeshellarg
  • Loading branch information
Ned Zimmerman committed Oct 11, 2018
1 parent 7b94ab4 commit a06dc96
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions inc/stats/namespace.php
Expand Up @@ -492,8 +492,9 @@ function display_network_storage() {
}

function calculate_network_storage() {
$path = wp_upload_dir()['basedir'];
$storage = format_bytes( rtrim( str_replace( $path, '', `du -b -s $path` ) ) );
$path = realpath( wp_upload_dir()['basedir'] );
$output = exec( sprintf( 'du -b -s %s', escapeshellarg( $path ) ) );
$storage = format_bytes( rtrim( str_replace( $path, '', $output ) ) );
return $storage;
}

Expand Down

0 comments on commit a06dc96

Please sign in to comment.