You are here

function _s3fs_load_awssdk2_library in S3 File System 7.2

Same name and namespace in other branches
  1. 7 s3fs.module \_s3fs_load_awssdk2_library()

Loads the awssdk2 library.

This function is a replacement for calling libraries_load('awsdsk2'). It's needed because libraries_load() caches failures to load the library, meaning that temporarily having a bad setup (e.g. nonexistent or unreadable files in the awssdk2 folder) can lead to the library being permanently unable to be loaded, even after the bad setup is repaired. This can only be remedied by clearing the full site cache.

This is especially disasterous when upgrading the awssdk2 library on a system that is currently using it, because if the upgrade results in a bad setup, the site cache may become impossible to clear. If some other module's data has been cached in S3 (e.g. ctools css cache), the cache clearing process itself will attempt to use S3FS. But if Libaries' cache has not yet been cleared by this time, it will continue to insist that awssdk2 is not installed, and the cache clear will crash because s3fs can't function without the awssdk2 library. This leaves the site in an unrecoverable broken state.

Return value

array The array returned by libraries_load('awssdk2'), as if it used no cache.

2 calls to _s3fs_load_awssdk2_library()
S3fsStreamWrapper.inc in ./S3fsStreamWrapper.inc
Drupal stream wrapper implementation for S3 File System.
_s3fs_get_amazons3_client in ./s3fs.module
Sets up the S3Client object.

File

./s3fs.module, line 900
Hook implementations and other primary functionality for S3 File System.

Code

function _s3fs_load_awssdk2_library() {

  // Start by calling libraries_load().
  $library = libraries_load('awssdk2');

  // If it detects and loads the library, great! We're done.
  if (!empty($library['loaded'])) {
    return $library;
  }

  // Otherwise, clear the awssdk2 value from the Libraries cache, erase the
  // static data for libraries_load(), then call it again to get the real
  // state of the library.
  cache_clear_all('awssdk2', 'cache_libraries');
  drupal_static_reset('libraries_load');
  return libraries_load('awssdk2');
}