コード例 #1
0
 /**
  * Normalise the exclude rules so they are ready to work with.
  *
  * @param array $excludes The array of exclude rules to normalise.
  *
  * @return array          The array of normalised rules.
  */
 public function normalize($excludes)
 {
     $excludes = array_map(function ($exclude) {
         // Convert absolute paths to relative.
         $exclude = str_replace(PATH::get_root(), '', wp_normalize_path($exclude));
         // Trim the slashes.
         $exclude = trim($exclude);
         $exclude = ltrim($exclude, '/');
         $exclude = untrailingslashit($exclude);
         return $exclude;
     }, $excludes);
     // Remove duplicate or empty rules.
     $excludes = array_unique($excludes);
     $excludes = array_filter($excludes);
     return $excludes;
 }
コード例 #2
0
 public function directory_filesize(\SplFileInfo $file)
 {
     // For performance reasons we cache the root.
     if ($file->getRealPath() === PATH::get_root() && $this->excludes) {
         $directory_sizes = get_transient('hmbkp_root_size');
         if ($directory_sizes) {
             return $directory_sizes;
         }
     }
     // If we haven't calculated the site size yet then kick it off in a thread
     $directory_sizes = $this->get_cached_filesizes();
     if (!is_array($directory_sizes)) {
         $this->rebuild_directory_filesizes();
         // Intentionally return null so the caller can tell that the size is being calculated
         return null;
     }
     /*
      * Ensure we only include files in the current path, the filepaths are stored in keys
      * so we need to flip for use with preg_grep.
      */
     $directory_sizes = array_flip(preg_grep('(' . wp_normalize_path($file->getRealPath()) . ')', array_flip($directory_sizes)));
     if ($this->excludes) {
         $excludes = implode('|', $this->excludes->get_excludes_for_regex());
         if ($excludes) {
             // Use PREG_GREP_INVERT to remove any filepaths which match an exclude rule
             $directory_sizes = array_flip(preg_grep('(' . $excludes . ')', array_flip($directory_sizes), PREG_GREP_INVERT));
         }
     }
     $directory_sizes = absint(array_sum($directory_sizes));
     // For performance reasons we cache the root.
     if ($file->getRealPath() === PATH::get_root() && $this->excludes) {
         set_transient('hmbkp_root_size', $directory_sizes, DAY_IN_SECONDS);
     }
     // Directory size is now just a sum of all files across all sub directories.
     return $directory_sizes;
 }
コード例 #3
0
 public function test_file_with_strange_characters()
 {
     file_put_contents(PATH::get_root() . '/Groß.jpg', '');
     $this->assertFileExists(PATH::get_root() . '/Groß.jpg');
     $this->backup->backup();
     $this->assertFileExists($this->backup->get_backup_filepath());
     $this->assertArchiveContains($this->backup->get_backup_filepath(), array('Groß.jpg'));
     unlink(PATH::get_root() . '/Groß.jpg');
 }