Пример #1
0
 /**
  * Begin the file system transaction.
  * Create the journal path and copy all files to it from the original path.
  *
  * @return void
  */
 public function begin()
 {
     if ($this->inTransaction) {
         throw new RuntimeException('Cannot begin - already in a transaction');
     }
     $this->inTransaction = true;
     // Remove possible failed transaction
     if (file_exists($this->journalPath)) {
         if (!is_dir($this->journalPath)) {
             throw new IOException('unrecoverable transaction error: journal path ' . $this->journalPath . ' exists and is not a directory');
         }
         FS::rmrf($this->journalPath);
     }
     // Create the journal directory
     @mkdir($this->journalPath, 0755, true);
     if (!is_dir($this->journalPath)) {
         throw new IOException('unrecoverable transaction error: cannot create journal path ' . $this->journalPath);
     }
     // Set permissions
     chmod($this->journalPath, file_exists($this->path) ? fileperms($this->path) : $this->getMode());
     // Copy source to the journal
     FS::copyDir($this->path, $this->journalPath);
 }