Skip to content

Commit

Permalink
Merge pull request #67 from webosbrew/fix/ls-compatible-option
Browse files Browse the repository at this point in the history
Fix/ls compatible option
  • Loading branch information
mariotaku authored Feb 12, 2023
2 parents 1262deb + 916ef7b commit e53501f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dev-manager-desktop",
"version": "1.9.7",
"version": "1.9.8",
"description": "Device Manager for webOS",
"homepage": "https://github.com/webosbrew/dev-manager-desktop",
"author": {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod device_manager;
mod plugins;
mod session_manager;
mod error;
mod ssh_files;

fn main() {
env_logger::init();
Expand Down
30 changes: 13 additions & 17 deletions src-tauri/src/plugins/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::device_manager::Device;
use crate::error::Error;
use crate::plugins::cmd::escape_path;
use crate::session_manager::SessionManager;
use crate::ssh_files::ls::for_entries;

#[tauri::command]
async fn ls(
Expand Down Expand Up @@ -41,24 +42,19 @@ async fn ls(
entries.pop();
entries.sort();
let mut items = Vec::<FileItem>::new();
let mut ls_legacy = false;
for chunk in entries.chunks(100) {
let ls_input = chunk.join("\0").into_bytes();
let mut details: Vec<String> = String::from_utf8(
manager
.exec(
device.clone(),
"xargs -0 ls -ld --full-time",
Some(ls_input),
)
.await?,
)
.unwrap()
.split('\n')
.map(|l| String::from(l))
.collect();
// Last line is empty, remove it
details.pop();
assert_eq!(chunk.len(), details.len());
let details = match for_entries(&manager, device.clone(), chunk, ls_legacy).await {
Ok(details) => details,
Err(Error::Unsupported) => {
if ls_legacy {
return Err(Error::Unsupported);
}
ls_legacy = true;
for_entries(&manager, device.clone(), chunk, true).await?
}
Err(e) => return Err(e),
};
let mut group: Vec<FileItem> = zip(chunk, details)
.skip(1)
.map(|(entry, line)| {
Expand Down
49 changes: 49 additions & 0 deletions src-tauri/src/ssh_files/ls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::device_manager::Device;
use crate::error::Error;
use crate::session_manager::SessionManager;

pub(crate) async fn for_entries(
manager: &SessionManager,
device: Device,
entries: &[String],
use_legacy: bool,
) -> Result<Vec<String>, Error> {
let ls_input = entries.join("\0").into_bytes();
let ls_output = match manager
.exec(
device.clone(),
&format!(
"xargs -0 ls -ld {}",
if use_legacy { "-e" } else { "--full-time" }
),
Some(ls_input.clone()),
)
.await
{
Ok(v) => v,
Err(Error::ExitStatus {
message,
exit_code,
stderr,
}) => {
if exit_code == 123 {
return Err(Error::Unsupported);
}
return Err(Error::ExitStatus {
message,
exit_code,
stderr,
});
}
Err(e) => return Err(e),
};
let mut details: Vec<String> = String::from_utf8(ls_output)
.unwrap()
.split('\n')
.map(|l| String::from(l))
.collect();
// Last line is empty, remove it
details.pop();
assert_eq!(entries.len(), details.len());
return Ok(details);
}
1 change: 1 addition & 0 deletions src-tauri/src/ssh_files/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod ls;

0 comments on commit e53501f

Please sign in to comment.