Skip to content

Commit

Permalink
Use is_readable instead of file_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kadamwhite committed Jul 21, 2020
1 parent b939081 commit 4e04c42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions inc/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ function get_version( string $asset_uri, string $manifest_path ) : ?string {
if ( $manifest_hash ) {
$manifest_hashes[ $manifest_path ] = $manifest_hash;
return $manifest_hashes[ $manifest_path ];
} else {
// Set "null" to prevent trying to re-hash after hashing has failed once.
$manifest_hashes[ $manifest_path ] = null;
}
} else {
// Set "null" to prevent subsequent file_exists checks during this request.
$manifest_hashes[ $manifest_path ] = null;
}

// Finally, use the Altis deployment revision when available. This is a
Expand Down
8 changes: 4 additions & 4 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function( $script_key ) use ( $target_bundle ) {
$css_bundle = $build_path . preg_replace( '/\.js$/', '.css', $target_bundle );

// Production mode. Manually register script bundles.
if ( file_exists( $js_bundle ) ) {
if ( is_readable( $js_bundle ) ) {
wp_register_script(
$options['handle'],
Paths\get_file_uri( $js_bundle ),
Expand All @@ -196,7 +196,7 @@ function( $script_key ) use ( $target_bundle ) {
$registered['scripts'][] = $options['handle'];
}

if ( file_exists( $css_bundle ) ) {
if ( is_readable( $css_bundle ) ) {
wp_register_style(
$options['handle'],
Paths\get_file_uri( $css_bundle ),
Expand Down Expand Up @@ -338,8 +338,8 @@ function register_asset( string $manifest_path, string $target_asset, array $opt

// If asset is not present in manifest, attempt to resolve the $target_asset
// relative to the folder containing the manifest file.
if ( empty( $asset_uri ) && file_exists( $manifest_folder . $target_asset ) ) {
// TODO: Consider checking file_exists( $manifest_folder . $target_asset )
if ( empty( $asset_uri ) && is_readable( $manifest_folder . $target_asset ) ) {
// TODO: Consider checking is_readable( $manifest_folder . $target_asset )
// and warning (in console or error log) if it is not present on disk.
$asset_uri = $target_asset;
}
Expand Down

0 comments on commit 4e04c42

Please sign in to comment.