Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added copy function, test, and docs. #5

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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