/**
  * @param File $file
  */
 protected function processFile(File $file)
 {
     $placeholder = Config::inst()->get('CloudAssets', 'file_placeholder');
     // 6. Local needs to be wrapped or uploaded             -> uploads as normal (via updateCloudStatus)
     $file->updateCloudStatus();
     $bucket = $file->getCloudBucket();
     if ($bucket && $bucket->hasMethod('getFileSize')) {
         $size = $bucket->getFileSize($file);
         // if the size matches the placeholder, go ahead and check the actual contents
         if ($size === strlen($placeholder)) {
             echo " Remote placeholder!";
             $content = $bucket->getContents($file);
             if ($content === $placeholder) {
                 $size = -1;
             }
         }
         if ($size < 0) {
             if ($file->isLocalMissing()) {
                 // 5. Both remote and local are missing or corrupt      -> deletes if thumbnail, flags if not (writes to missing_files.csv)
                 if ($file instanceof CloudImageCached) {
                     echo " Corrupted thumbnail deleted";
                     $file->delete();
                     return;
                 } else {
                     if (!isset($this->missing)) {
                         $this->missing = fopen(BASE_PATH . '/missing_files.csv', 'a');
                     }
                     fputcsv($this->missing, array(date('Y-m-d H:i:s'), $file->ID, $file->Filename));
                     echo " Corrupted in both locations!!!";
                     return;
                 }
             } else {
                 // 3. Remote file is a placeholder but local in tact    -> clears status and re-uploads
                 $file->CloudStatus = 'Local';
                 $file->updateCloudStatus();
             }
         }
     }
     // 1. Local file doesn't exist                          -> downloads from cloud
     // 2. Local file is a placeholder but KeepLocal is true -> downloads from cloud
     $file->createLocalIfNeeded();
     // 4. Meta data is missing                              -> restores meta
     if ($file instanceof CloudImage && !$file->getCloudMeta('Dimensions')) {
         echo " Missing metadata!";
         if ($file->isLocalMissing()) {
             $file->downloadFromCloud();
         }
         $file->setCloudMeta('Dimensions', $file->getDimensions('live'));
         $file->write();
     }
 }
 /**
  * If this file is stored in the cloud, downloads the cloud
  * copy and replaces whatever is local.
  */
 public function downloadFromCloud()
 {
     if ($this->owner->CloudStatus === 'Live') {
         $bucket = $this->owner->getCloudBucket();
         if ($bucket) {
             $contents = $bucket->getContents($this->owner);
             $path = $this->owner->getFullPath();
             Filesystem::makeFolder(dirname($path));
             CloudAssets::inst()->getLogger()->debug("CloudAssets: downloading {$path} from cloud (size=" . strlen($contents) . ")");
             // if there was an error and we overwrote the local file with empty or null, it could delete the remote
             // file as well. Better to err on the side of not writing locally when we should than that.
             if (!empty($contents)) {
                 file_put_contents($path, $contents);
             }
         }
     }
 }