Skip to content

Commit

Permalink
remove unnecessary clone
Browse files Browse the repository at this point in the history
  • Loading branch information
VoyTechnology committed Mar 13, 2018
1 parent 29a37ff commit 480bbd0
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions worker/src/state/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ const PENDING_REDUCE_DIR: &str = "pending_reduce_tasks";

pub struct FileStore {
path: PathBuf,
jobs_path: PathBuf,
}

impl FileStore {
pub fn new(path: &PathBuf) -> Result<Self, StateError> {
Ok(FileStore {
path: path.clone(),
jobs_path: path.clone().join(JOBS_DIR),
})
Ok(FileStore { path: path.clone() })
}

/// Creates the path to the job from the given `job_id`.
fn job_dir_path(&self, job_id: &str) -> PathBuf {
self.jobs_path.clone().join(job_id)
self.path.join(JOBS_DIR).join(job_id)
}
}

Expand All @@ -37,7 +33,7 @@ impl State for FileStore {
let job_dir_path = self.job_dir_path(task.get_job_id());
let task_id = task.get_id();

let task_file_path = job_dir_path.clone().join(TASKS_DIR).join(&task_id);
let task_file_path = job_dir_path.join(TASKS_DIR).join(&task_id);
if !task_file_path.exists() {
return Err(StateErrorKind::MissingTask.into());
}
Expand Down Expand Up @@ -81,20 +77,18 @@ mod tests {
fn setup(test_path: &PathBuf, task_id: &str) {
fs::create_dir_all(&test_path).unwrap();

let mut test_tasks_path = test_path.clone().join(TASKS_DIR);
let test_tasks_path = test_path.join(TASKS_DIR);
fs::create_dir_all(&test_tasks_path).unwrap();
// File content doesn't matter, we don't really care about it.
let mut test_tasks_file = test_tasks_path.clone().join(&task_id);
File::create(test_tasks_file)
File::create(test_tasks_path.join(&task_id))
.unwrap()
.write_all(task_id.clone().as_bytes())
.write_all(task_id.as_bytes())
.unwrap();

let mut test_pending_tasks_path = test_path.clone().join(PENDING_MAP_DIR);
let test_pending_tasks_path = test_path.join(PENDING_MAP_DIR);
fs::create_dir_all(&test_pending_tasks_path).unwrap();
// File content doesn't matter
let mut test_pending_tasks_file = test_pending_tasks_path.clone().join(&task_id);
File::create(test_pending_tasks_file)
File::create(test_pending_tasks_path.join(&task_id))
.unwrap()
.write_all(task_id.clone().as_bytes())
.unwrap();
Expand Down Expand Up @@ -131,18 +125,12 @@ mod tests {
test_task.set_status(TaskStatus::TASK_IN_PROGRESS);
st.save_progress(&test_task).unwrap();

assert_eq!(
true,
check_map_exists(&test_job_path, task_id.clone())
);
assert_eq!(true, check_map_exists(&test_job_path, task_id.clone()));

test_task.set_status(TaskStatus::TASK_DONE);
st.save_progress(&test_task).unwrap();

assert_eq!(
false,
check_map_exists(&test_job_path, task_id.clone())
);
assert_eq!(false, check_map_exists(&test_job_path, task_id.clone()));

cleanup(&test_dir);
}
Expand Down

0 comments on commit 480bbd0

Please sign in to comment.