Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Applying patch from 'Ceeram'. Adds File::copy() and test case. Refs #150

  • Loading branch information...
commit 8d40532931827697ee2653e9eafc035d433632c5 1 parent ee7015c
@markstory markstory authored
Showing with 45 additions and 1 deletion.
  1. +16 −1 cake/libs/file.php
  2. +29 −0 cake/tests/cases/libs/file.test.php
View
17 cake/libs/file.php
@@ -314,7 +314,7 @@ function delete() {
}
/**
- * Returns the File extension.
+ * Returns the File info.
*
* @return string The File extension
* @access public
@@ -540,5 +540,20 @@ function lastChange() {
function &Folder() {
return $this->Folder;
}
+
+/**
+ * Copy the File to $dest
+ *
+ * @param string $dest destination for the copy
+ * @param boolean $overwrite Overwrite $dest if exists
+ * @return boolean Succes
+ * @access public
+ */
+ function copy($dest, $overwrite = true) {
+ if (!$this->exists() || is_file($dest) && !$overwrite) {
+ return false;
+ }
+ return copy($this->path, $dest);
+ }
}
?>
View
29 cake/tests/cases/libs/file.test.php
@@ -417,6 +417,35 @@ function testDelete() {
}
/**
+ * testCopy method
+ *
+ * @access public
+ * @return void
+ */
+ function testCopy() {
+ $dest = TMP . 'tests' . DS . 'cakephp.file.test.tmp';
+ $file = __FILE__;
+ $this->File =& new File($file);
+ $result = $this->File->copy($dest);
+ $this->assertTrue($result);
+
+ $result = $this->File->copy($dest, true);
+ $this->assertTrue($result);
+
+ $result = $this->File->copy($dest, false);
+ $this->assertFalse($result);
+
+ $this->File->close();
+ unlink($dest);
+
+ $TmpFile =& new File('/this/does/not/exist');
+ $result = $TmpFile->copy($dest);
+ $this->assertFalse($result);
+
+ $TmpFile->close();
+ }
+
+/**
* getTmpFile method
*
* @param bool $paintSkip
Please sign in to comment.
Something went wrong with that request. Please try again.