Skip to content

Commit 097e1d4

Browse files
committed
chore: remove unused files
1 parent 0634ec9 commit 097e1d4

File tree

5 files changed

+41
-165
lines changed

5 files changed

+41
-165
lines changed

src/args.rs

Lines changed: 0 additions & 150 deletions
This file was deleted.

src/backup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Backup files that we are about to override, to make sure the user does not
22
//! lose any work
33
use std::ffi::OsString;
4-
use std::fs::{File, ReadDir, read_to_string};
4+
use std::fs::{self, File, ReadDir};
55
use std::io::Write as _;
66
use std::path::PathBuf;
77

@@ -17,7 +17,7 @@ pub fn files(config_files: ReadDir) -> anyhow::Result<Vec<(OsString, File, Strin
1717
let config_file = entry?;
1818

1919
let path = config_file.path();
20-
let contents = read_to_string(&path)?;
20+
let contents = fs::read_to_string(&path)?;
2121

2222
let filename = config_file.file_name();
2323
let mut destination_backed_up = tempfile()?;

src/commands/run.rs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
use std::fs;
1+
use std::fs::{self, File};
2+
use std::io::Write as _;
3+
use std::path::PathBuf;
24

35
use anyhow::{anyhow, bail};
46
use colored::Colorize as _;
57

68
use crate::commands::pr_fetch::ignore_octothorpe;
79
use crate::commit::Commit;
810
use crate::git::{self, GIT_ROOT, git};
11+
use crate::note;
912
use crate::types::{Branch, BranchAndRemote, Configuration, Remote};
1013
use crate::utils::{display_link, with_uuid};
1114
use crate::{APP_NAME, CONFIG_FILE, CONFIG_ROOT, commands, confirm_prompt, fail, success};
12-
use crate::{backup, note};
1315

1416
/// Parses user inputs of the form `<head><syntax><commit-hash>`
1517
///
@@ -82,8 +84,33 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
8284
)
8385
})?;
8486

85-
let backed_up_files = backup::files(config_files)
86-
.map_err(|err| anyhow!("Failed to create backups for configuration files:\n{err}"))?;
87+
let backed_up_files = {
88+
let mut backups = Vec::new();
89+
90+
for config_file in config_files {
91+
let config_file = config_file?;
92+
93+
let path = config_file.path();
94+
let backup = fs::read_to_string(&path)
95+
.map_err(|err| anyhow!("{err}"))
96+
.and_then(|contents| {
97+
let filename = config_file.file_name();
98+
let mut destination_backed_up =
99+
tempfile::tempfile().map_err(|err| anyhow!("{err}"))?;
100+
101+
write!(destination_backed_up, "{contents}")?;
102+
103+
Ok((filename, destination_backed_up, contents))
104+
})
105+
.map_err(|err| {
106+
anyhow!("Failed to create backups for configuration files:\n{err}")
107+
})?;
108+
109+
backups.push(backup);
110+
}
111+
112+
backups
113+
};
87114

88115
let info = BranchAndRemote {
89116
branch: Branch {
@@ -164,15 +191,15 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
164191
&info.branch.local_branch_name,
165192
)?;
166193

167-
return Err(anyhow!(
168-
"Could not create directory {}\n{err}",
169-
CONFIG_ROOT.as_str()
170-
));
194+
bail!("Could not create directory {}\n{err}", CONFIG_ROOT.as_str());
171195
}
172196

173197
for (file_name, _file, contents) in &backed_up_files {
174-
backup::restore(file_name, contents)
175-
.map_err(|err| anyhow!("Could not restore backups:\n{err}"))?;
198+
let path = GIT_ROOT.join(PathBuf::from(CONFIG_ROOT.as_str()).join(file_name));
199+
let mut file =
200+
File::create(&path).map_err(|err| anyhow!("failed to restore backup: {err}"))?;
201+
202+
write!(file, "{contents}")?;
176203
}
177204

178205
// apply patches if they exist

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use std::env;
33
use std::sync::LazyLock;
44

5-
mod backup;
65
mod cli;
76
mod commands;
87
mod commit;

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use clap::Parser as _;
2-
31
use std::process::ExitCode;
42

3+
use clap::Parser as _;
4+
55
#[tokio::main]
66
async fn main() -> ExitCode {
77
if let Err(err) = patchy::Cli::parse().command.execute().await {

0 commit comments

Comments
 (0)