private function copyFile($sourcePath, $destPath, $flags = 0) { if (!file_exists($sourcePath)) { // Abort! Abort! throw new FSException("missing source file '{$sourcePath}'\n"); } $transaction = new FSTransaction(); if ($flags & self::DELETE_ORIGINAL) { $transaction->addCommit(FSTransaction::DELETE_FILE, $sourcePath); } if (file_exists($destPath)) { // An identical file is already present; no need to copy. } else { if (!file_exists(dirname($destPath))) { wfSuppressWarnings(); $ok = mkdir(dirname($destPath), 0777, true); wfRestoreWarnings(); if (!$ok) { throw new FSException("failed to create directory for '{$destPath}'\n"); } } wfSuppressWarnings(); $ok = copy($sourcePath, $destPath); wfRestoreWarnings(); if ($ok) { wfDebug(__METHOD__ . " copied '{$sourcePath}' to '{$destPath}'\n"); $transaction->addRollback(FSTransaction::DELETE_FILE, $destPath); } else { throw new FSException(__METHOD__ . " failed to copy '{$sourcePath}' to '{$destPath}'\n"); } } return $transaction; }