示例#1
0
 /**
  * Rolls back a filesystem transaction, it is safe to rollback when no transaction is in progress
  * 
  * @return void
  */
 public static function rollback()
 {
     if (self::$rollback_operations === NULL) {
         return;
     }
     self::$rollback_operations = array_reverse(self::$rollback_operations);
     foreach (self::$rollback_operations as $operation) {
         switch ($operation['action']) {
             case 'append':
                 $current_length = filesize($operation['filename']);
                 $handle = fopen($operation['filename'], 'r+');
                 ftruncate($handle, $current_length - $operation['length']);
                 fclose($handle);
                 break;
             case 'delete':
                 self::updateDeletedMap($operation['filename'], debug_backtrace());
                 unlink($operation['filename']);
                 fFilesystem::updateFilenameMap($operation['filename'], '*DELETED at ' . time() . ' with token ' . uniqid('', TRUE) . '* ' . $operation['filename']);
                 break;
             case 'write':
                 file_put_contents($operation['filename'], $operation['old_data']);
                 break;
             case 'rename':
                 fFilesystem::updateFilenameMap($operation['new_name'], $operation['old_name']);
                 rename($operation['new_name'], $operation['old_name']);
                 break;
         }
     }
     // All files to be deleted should have their backtraces erased
     foreach (self::$commit_operations as $operation) {
         if (isset($operation['object'])) {
             self::updateDeletedMap($operation['object']->getPath(), NULL);
             fFilesystem::updateFilenameMap($operation['object']->getPath(), preg_replace('#*DELETED at \\d+ with token [\\w.]+* #', '', $operation['filename']));
         }
     }
     self::$commit_operations = NULL;
     self::$rollback_operations = NULL;
 }
示例#2
0
 /**
  * Rolls back a filesystem transaction, it is safe to rollback when no transaction is in progress
  * 
  * @return void
  */
 public static function rollback()
 {
     self::$rollback_operations = array_reverse(self::$rollback_operations);
     foreach (self::$rollback_operations as $operation) {
         switch ($operation['action']) {
             case 'delete':
                 self::updateExceptionMap($operation['filename'], new fProgrammerException('The action requested can not be performed because the file has been deleted'));
                 unlink($operation['filename']);
                 break;
             case 'write':
                 file_put_contents($operation['filename'], $operation['old_data']);
                 break;
             case 'rename':
                 fFilesystem::updateFilenameMap($operation['new_name'], $operation['old_name']);
                 rename($operation['new_name'], $operation['old_name']);
                 break;
         }
     }
     // All files to be deleted should have their exceptions erased
     foreach (self::$commit_operations as $operation) {
         if (isset($operation['object'])) {
             self::updateExceptionMap($operation['object']->getPath(), NULL);
         }
     }
     self::$commit_operations = NULL;
     self::$rollback_operations = NULL;
 }