pub async fn process_get_command(
    safe: &mut Safe,
    source: XorUrl,
    dest: Option<String>,
    exists: FileExistsAction,
    progress: ProgressIndicator,
    _preserve: bool,
    _output_fmt: OutputFmt,
) -> Result<()> {
    let str_path = dest.unwrap_or_else(|| ".".to_string());
    let path = Path::new(&str_path);

    let (mp, bars) = create_progress_bars();

    let mut overwrites: u64 = 0;
    let mut preserves: u64 = 0;

    let (_version, processed_files) =
        files_container_get_files(safe, &source, &str_path, |status| {
            let mut overwrite = true;
            let mut mystatus = status.clone();

            if status.file_bytes_written == 0 {
                // It is an error/warning if the dest path attempts to use
                // an existing file as a directory. But other files should
                // still be written.  eg:
                // $ mkdir -p /tmp/a/b/c && touch /tmp/a/file.txt
                // $ mkdir /tmp/target && touch /tmp/target/b   (b is a file)
                // $ cp -r /tmp/a/* /tmp/target
                //    cp: cannot overwrite non-directory '/tmp/target/b' with directory '/tmp/a/b'
                // $ ls -l /tmp/target/
                //      total 0
                //      -rw-rw-r-- 1 user user 0 Mar 31 14:38 b         (b still a file)
                //      -rw-rw-r-- 1 user user 0 Mar 31 14:38 file.txt  (other file written)
                //
                // TBD: Should FileExistsAction apply to this case?
                //      unix cp does not provide any flag/option/prompt to permit this
                //      and it always emits a warning.  So I am satisfied with this
                //      working the same way, at least for now.
                let dirpath = if status.file_type == "inode/directory" {
                    Some(status.path_local)
                } else {
                    status.path_local.parent()
                };
                if let Some(parent) = dirpath {
                    if let Some(filepath) = path_contains_file(parent) {
                        let msg = format!(
                            "cannot overwrite non-directory '{}' with directory in '{}'",
                            filepath.display(),
                            status.path_local.display()
                        );

                        warn!("Skipping file \"{}\". {}", status.path_local.display(), msg);
                        if isatty::stderr_isatty() {
                            eprintln!("Warning: {}", msg);
                        }
                        overwrite = false;
                    }
                }
                if status.path_local.exists() && overwrite {
                    overwrite = match exists {
                        FileExistsAction::Overwrite => true,
                        FileExistsAction::Preserve => false,
                        FileExistsAction::Ask => {
                            let prompt = format!(
                                "overwrite '{}'? ",
                                status.path_local.display().to_string()
                            );
                            prompt_yes_no(&prompt, "Y")
                        }
                    };
                    if overwrite {
                        overwrites += 1;
                    } else {
                        preserves += 1;
                        mystatus.total_transfer_bytes -= mystatus.file_size;
                    }
                }
            }
            if overwrite {
                match progress {
                    ProgressIndicator::Bars => {
                        update_progress_bars(&mp, &bars, &mystatus);
                    }
                    ProgressIndicator::Text => {
                        print_status(status);
                    }
                    ProgressIndicator::None => {}
                }
            }
            overwrite
        })
        .await?;

    if processed_files.is_empty() && preserves == 0 {
        bail!("Path '{}' not found", path.display());
    }

    print_results(&processed_files, path, overwrites, preserves);

    Ok(())
}
// processes the `safe files get` command.  called by files.rs
//
// dest is a local path.  defaults to "."
//   Path will be created if not existing, else error.
//
// TODO: _preserve file attributes is not yet implemented, we need them
//   stored in metadata first.
//
// TBD: how should we handle OutputFmt?  Presently, we are displaying
// progress bars, and also [possibly] prompting user about overwrites.
// We have a list of processed files that we could present as json
// or in table form.  But if stdout format is json and we prompt user,
// then any process parsing output as json will break.  So possibly
// --exists=ask and --json should conflict and not be allowed.
//
// This command is really similar to cp or scp, and people are fine
// using those without a report.  So it doesn't seem especially urgent.
processes the `safe files get` command.  called by files.rs
dest is a local path.  defaults to "."
Path will be created if not existing, else error.

_preserve file attributes is not yet implemented, we need them
stored in metadata first.



This command is really similar to cp or scp, and people are fine
using those without a report.  So it doesn't seem especially urgent.
processes the ` safe files get ` command . called by files . rs dest is a local path . defaults to " . " Path will be created if not existing else error . _preserve file attributes is not yet implemented we need them stored in metadata first . This command is really similar to cp or scp and people are fine using those without a report . So it doesn ' t seem especially urgent .
pub async fn process_get_command(
    safe: &mut Safe,
    source: XorUrl,
    dest: Option<String>,
    exists: FileExistsAction,
    progress: ProgressIndicator,
    _preserve: bool,
    _output_fmt: OutputFmt,
) -> Result<()> {
    let str_path = dest.unwrap_or_else(|| ".".to_string());
    let path = Path::new(&str_path);
    let (mp, bars) = create_progress_bars();
    let mut overwrites: u64 = 0;
    let mut preserves: u64 = 0;
    let (_version, processed_files) =
        files_container_get_files(safe, &source, &str_path, |status| {
            let mut overwrite = true;
            let mut mystatus = status.clone();
            if status.file_bytes_written == 0 {
                // It is an error/warning if the dest path attempts to use
                // an existing file as a directory. But other files should
                // still be written.  eg:
                // $ mkdir -p /tmp/a/b/c && touch /tmp/a/file.txt
                // $ mkdir /tmp/target && touch /tmp/target/b   (b is a file)
                // $ cp -r /tmp/a/* /tmp/target
                //    cp: cannot overwrite non-directory '/tmp/target/b' with directory '/tmp/a/b'
                // $ ls -l /tmp/target/
                //      total 0
                //      -rw-rw-r-- 1 user user 0 Mar 31 14:38 b         (b still a file)
                //      -rw-rw-r-- 1 user user 0 Mar 31 14:38 file.txt  (other file written)
                //
                // TBD: Should FileExistsAction apply to this case?
                //      unix cp does not provide any flag/option/prompt to permit this
                //      and it always emits a warning.  So I am satisfied with this
                //      working the same way, at least for now.
                let dirpath = if status.file_type == "inode/directory" {
                    Some(status.path_local)
                } else {
                    status.path_local.parent()
                };
                if let Some(parent) = dirpath {
                    if let Some(filepath) = path_contains_file(parent) {
                        let msg = format!(
                            "cannot overwrite non-directory '{}' with directory in '{}'",
                            filepath.display(),
                            status.path_local.display()
                        );
                        warn!("Skipping file \"{}\". {}", status.path_local.display(), msg);
                        if isatty::stderr_isatty() {
                            eprintln!("Warning: {}", msg);
                        }
                        overwrite = false;
                    }
                }
                if status.path_local.exists() && overwrite {
                    overwrite = match exists {
                        FileExistsAction::Overwrite => true,
                        FileExistsAction::Preserve => false,
                        FileExistsAction::Ask => {
                            let prompt = format!(
                                "overwrite '{}'? ",
                                status.path_local.display().to_string()
                            );
                            prompt_yes_no(&prompt, "Y")
                        }
                    };
                    if overwrite {
                        overwrites += 1;
                    } else {
                        preserves += 1;
                        mystatus.total_transfer_bytes -= mystatus.file_size;
                    }
                }
            }
            if overwrite {
                match progress {
                    ProgressIndicator::Bars => {
                        update_progress_bars(&mp, &bars, &mystatus);
                    }
                    ProgressIndicator::Text => {
                        print_status(status);
                    }
                    ProgressIndicator::None => {}
                }
            }
            overwrite
        })
        .await?;
    if processed_files.is_empty() && preserves == 0 {
        bail!("Path '{}' not found", path.display());
    }
    print_results(&processed_files, path, overwrites, preserves);
    Ok(())
}
pub async fn process_get_command ( safe : & mut Safe , source : XorUrl , dest : Option < String > , exists : FileExistsAction , progress : ProgressIndicator , _preserve : bool , _output_fmt : OutputFmt , ) -> Result < ( ) > { let str_path = dest . unwrap_or_else ( | | " " . to_string ( ) ) ; let path = Path :: new ( & str_path ) ; let ( mp , bars ) = create_progress_bars ( ) ; let mut overwrites : u64 = 0 ; let mut preserves : u64 = 0 ; let ( _version , processed_files ) = files_container_get_files ( safe , & source , & str_path , | status | { let mut overwrite = true ; let mut mystatus = status . clone ( ) ; if status . file_bytes_written == 0 { // It is an error/warning if the dest path attempts to use // an existing file as a directory. But other files should // still be written.  eg: // $ mkdir -p /tmp/a/b/c && touch /tmp/a/file.txt // $ mkdir /tmp/target && touch /tmp/target/b   (b is a file) // $ cp -r /tmp/a/* /tmp/target //    cp: cannot overwrite non-directory '/tmp/target/b' with directory '/tmp/a/b' // $ ls -l /tmp/target/ //      total 0 //      -rw-rw-r-- 1 user user 0 Mar 31 14:38 b         (b still a file) //      -rw-rw-r-- 1 user user 0 Mar 31 14:38 file.txt  (other file written) // // TBD: Should FileExistsAction apply to this case? //      unix cp does not provide any flag/option/prompt to permit this //      and it always emits a warning.  So I am satisfied with this //      working the same way, at least for now. let dirpath = if status . file_type == " " { Some ( status . path_local ) } else { status . path_local . parent ( ) } ; if let Some ( parent ) = dirpath { if let Some ( filepath ) = path_contains_file ( parent ) { let msg = format ! ( " " filepath display ( ) status path_local display ( ) ) ; warn ! ( " \" \" " status path_local display ( ) msg ) ; if isatty :: stderr_isatty ( ) { eprintln ! ( " " msg ) ; } overwrite = false ; } } if status . path_local . exists ( ) && overwrite { overwrite = match exists { FileExistsAction :: Overwrite => true , FileExistsAction :: Preserve => false , FileExistsAction :: Ask => { let prompt = format ! ( " " status path_local display ( ) to_string ( ) ) ; prompt_yes_no ( & prompt , " " ) } } ; if overwrite { overwrites += 1 ; } else { preserves += 1 ; mystatus . total_transfer_bytes -= mystatus . file_size ; } } } if overwrite { match progress { ProgressIndicator :: Bars => { update_progress_bars ( & mp , & bars , & mystatus ) ; } ProgressIndicator :: Text => { print_status ( status ) ; } ProgressIndicator :: None => { } } } overwrite } ) . await ? ; if processed_files . is_empty ( ) && preserves == 0 { bail ! ( " " path display ( ) ) ; } print_results ( & processed_files , path , overwrites , preserves ) ; Ok ( ( ) ) }
processes the `safe files get` command.
processes the ` safe files get ` command .
safe
&mut Safe
source
XorUrl
dest
Option<String>
exists
FileExistsAction
progress
ProgressIndicator
_preserve
bool
_output_fmt
OutputFmt