Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 5e0594c

Browse files
author
icelayer
committed
Added tilda in paths support [not tested]
1 parent 3907a8c commit 5e0594c

File tree

5 files changed

+53
-28
lines changed

5 files changed

+53
-28
lines changed

src/base/config.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#![allow(deprecated)]
2+
13
use crate::base::filesystem;
24
use directories::ProjectDirs;
35
use std::path::PathBuf;
46

5-
pub const VERSION: &str = "0.3.0";
6-
pub const DEV_MODE: bool = false;
7+
pub const VERSION: &str = "0.3.1-dev";
8+
pub const DEV_MODE: bool = true;
79
pub const SAFE_HISTORY: bool = true;
810

911
pub const SYS_BITS: u32 = 2048;
@@ -12,6 +14,18 @@ pub const BLOCK_BITS: u32 = 4096000;
1214

1315
pub const SUPPORTED_FORMATS: [&str; 2] = ["text", "file"];
1416

17+
pub fn linux_home_path() -> String {
18+
std::env::home_dir().unwrap().to_str().unwrap().to_string()
19+
}
20+
21+
pub fn tilda_to_abs_path(path_with_tilda: String) -> String {
22+
let mut path_with_tilda = path_with_tilda;
23+
if &path_with_tilda.chars().nth(0).unwrap() == &'~' {
24+
path_with_tilda = linux_home_path() + &path_with_tilda[1..];
25+
}
26+
path_with_tilda
27+
}
28+
1529
pub fn path() -> PathBuf {
1630
let result_path = ProjectDirs::from("su", "bald", "cwe-client")
1731
.unwrap()

src/command/export.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,27 @@ pub fn run() {
1212
return false;
1313
}
1414
}
15-
if !PathBuf::from(string).is_absolute() {
16-
return false;
17-
}
1815
return true;
1916
}
2017
loop {
2118
base::log(
2219
"Please enter ABSOLUTE path to export file: (example: /home/user/me.contact)",
2320
5,
2421
);
25-
let export_path = base::input("Export path: ");
26-
if check(export_path.clone()) {
27-
let server_host = base::config::default_url();
28-
let uuid = base::uuid::get();
29-
let public_key =
30-
base::filesystem::cat(&base::filesystem::new_path("base-keys/my-key.pub"));
22+
let export_path = base::correct_input("Export path: ", check);
23+
let export_path = base::config::tilda_to_abs_path(export_path);
24+
25+
let server_host = base::config::default_url();
26+
let uuid = base::uuid::get();
27+
let public_key = base::filesystem::cat(&base::filesystem::new_path("base-keys/my-key.pub"));
3128

32-
base::filesystem::echo(
33-
server_host + "\n" + &uuid + "\n" + &public_key,
34-
&PathBuf::from(export_path),
35-
);
29+
base::filesystem::echo(
30+
server_host + "\n" + &uuid + "\n" + &public_key,
31+
&PathBuf::from(export_path),
32+
);
3633

37-
base::log("Successfully exported your contact!", 0);
34+
base::log("Successfully exported your contact!", 0);
3835

39-
break;
40-
} else {
41-
base::log("Sorry, but this name is invalid", 3);
42-
}
36+
break;
4337
}
4438
}

src/command/history.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ pub fn run(passphrase: String) {
1212
return false;
1313
}
1414
}
15-
if !PathBuf::from(string).is_absolute() {
16-
return false;
17-
}
1815
return true;
1916
}
2017
let stored_messages_from = base::filesystem::ls(
@@ -104,6 +101,8 @@ pub fn run(passphrase: String) {
104101
);
105102

106103
let path = base::correct_input("Select place to extract data: ", check);
104+
let path = base::config::tilda_to_abs_path(path);
105+
107106
base::filesystem::becho(file, &PathBuf::from(path));
108107

109108
base::log("Extracted!", 0);

src/command/import.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,28 @@ use crate::base;
22
use std::path::PathBuf;
33

44
pub fn run() {
5-
base::log("Please enter ABSOLUTE path to contact file: ", 5);
6-
let path = base::correct_input("Path to contact: ", base::filesystem::exist_abs);
7-
if path == "exit".to_string() {
8-
return;
9-
}
5+
let path = {
6+
fn check(string: String) -> bool {
7+
let forbidden_chars = vec![
8+
" ", "\n", "\r", "\t", "\\", ":", "*", "?", "<", ">", "|", "&", "$", "!", "'",
9+
"\"", "`", "(", ")", "{", "}", "[", "]",
10+
];
11+
for forbidden_char in &forbidden_chars {
12+
if string.contains(forbidden_char) {
13+
return false;
14+
}
15+
}
16+
return true;
17+
}
18+
19+
base::log("Please enter path to contact file: ", 5);
20+
let path = base::correct_input("Path to contact: ", check);
21+
let path = base::config::tilda_to_abs_path(path);
22+
if path == "exit".to_string() {
23+
return;
24+
}
25+
path
26+
};
1027

1128
let lines = base::filesystem::cat_lines(&PathBuf::from(path.as_str()));
1229
let contact_server_host = lines[0].clone();

src/command/send.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn run(passphrase: String) {
2626
}
2727
"file" => {
2828
fn check(path: String) -> bool {
29+
let path = base::config::tilda_to_abs_path(path);
2930
if base::filesystem::get_file_name(path.clone()).contains('|') {
3031
false
3132
} else {

0 commit comments

Comments
 (0)