Skip to content

Commit

Permalink
fix: clippy format and empty folder scan error
Browse files Browse the repository at this point in the history
  • Loading branch information
MissterHao committed Nov 29, 2022
1 parent 1324f00 commit 0a0bc89
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/domain/entity/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ impl Workspace {
}

/// Strip uri prefix of decoded workspace path
#[cfg(target_os = "windows")]
pub fn strip_decode_path(&self) -> String {
let strip_uri_prefix = Regex::new(r"(file|vscode-remote):[/]+").unwrap();
strip_uri_prefix.replace(&self.decode_path, "").to_string()
}

/// Strip uri prefix of decoded workspace path
#[cfg(target_os = "linux")]
pub fn strip_decode_path(&self) -> String {
let strip_uri_prefix = Regex::new(r"(file|vscode-remote):[/][/]").unwrap();
strip_uri_prefix.replace(&self.decode_path, "").to_string()
Expand Down
2 changes: 1 addition & 1 deletion src/domain/searching/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl From<&str> for SearchingStrategy {
let tags = tag_re
.captures_iter(origin)
.map(|x| x.get(0).unwrap().as_str())
.map(|x| x.to_string().replace(' ', "").replace('#', ""))
.map(|x| x.to_string().replace([' ', '#'], ""))
.filter(|x| !x.is_empty())
.collect::<Vec<String>>();

Expand Down
20 changes: 12 additions & 8 deletions src/domain/system/folder_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ pub fn last_modified(workspace: &Workspace) -> Result<String, SystemError> {
let mut entries = result?;
entries.sort_by_cached_key(|f| f.metadata().unwrap().modified().unwrap());

let last_modified_secs = entries[0]
.metadata()
.unwrap()
.modified()
.unwrap()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
let last_modified_secs = if !(entries.is_empty()) {
entries[0]
.metadata()
.unwrap()
.modified()
.unwrap()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs()
} else {
0u64
};

Ok(Utc
.timestamp_opt(last_modified_secs as i64, 0)
Expand Down
9 changes: 3 additions & 6 deletions src/domain/system/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ pub fn scan_workspaces_path() -> Vec<Workspace> {
for json_path in current_workspaces_list.unwrap() {
let data = extract_json_file(json_path.as_str());

match data {
Some(val) => {
s.send(Some(Workspace::from(val)))
.expect("Fail to send Workspace struct to main receive channel.");
}
None => {}
if let Some(val) = data {
s.send(Some(Workspace::from(val)))
.expect("Fail to send Workspace struct to main receive channel.");
}
}
});
Expand Down

0 comments on commit 0a0bc89

Please sign in to comment.