Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 
Added copy function, test, and docs. (#5)

* Added copy function, test, and docs.
  • Loading branch information
hulto authored Mar 1, 2022
1 parent 5943875 commit 6317023
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
43 changes: 40 additions & 3 deletions cmd/implants/eldritch/src/file/copy_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
use anyhow::Result;
use std::fs;

pub fn copy(_src: String, _dst: String) -> Result<()> {
unimplemented!("Method unimplemented")
}
pub fn copy(src: String, dst: String) -> Result<()> {
fs::copy(src, dst)?;
Ok(())
}


#[cfg(test)]
mod tests {
use super::*;
use std::fs::File;
use std::io::prelude::*;
use std::fs::remove_file;

#[test]
fn test_copy() -> anyhow::Result<()>{
let _ = remove_file(String::from("/tmp/win_copy1"));
let _ = remove_file(String::from("/tmp/win_copy2"));

// Create file
let mut file = File::create("/tmp/win_copy1")?;
// Write to file
file.write_all(b"Hello, world!")?;

// Run our code
copy(String::from("/tmp/win_copy1"), String::from("/tmp/win_copy2"))?;

// Open copied file
let mut winfile = File::open("/tmp/win_copy2")?;
// Read
let mut contents = String::new();
winfile.read_to_string(&mut contents)?;
// Compare
assert_eq!(contents, "Hello, world!");

remove_file(String::from("/tmp/win_copy1"))?;
remove_file(String::from("/tmp/win_copy2"))?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion docs/_data/eldritch_nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- name: "file.copy"
signature: "file.copy(src: str, dst: str) -> None"
link: stdlib_file_copy
content: The <b>file.copy</b> method is very cool, and will be even cooler when Nick documents it.
content: The <b>file.copy</b> copies a file from src path to dst path. If dst path doesn't exist it will be created.
- name: "file.download"
signature: "file.download(uri: str, dst: str) -> None"
link: stdlib_file_download
Expand Down

0 comments on commit 6317023

Please sign in to comment.