/// Creates all the files listed in the manifest and resizes them to their
/// expected sizes.  This way we won't have to worry about creating parent
/// directories when we receive chunks.
Creates all the files listed in the manifest and resizes them to their
expected sizes.  This way we won't have to worry about creating parent
directories when we receive chunks.
Creates all the files listed in the manifest and resizes them to their expected sizes . This way we won ' t have to worry about creating parent directories when we receive chunks .
pub(crate) fn preallocate_layout(log: &ReplicaLogger, root: &Path, manifest: &Manifest) {
        for file_info in manifest.file_table.iter() {
            let path = root.join(&file_info.relative_path);
            std::fs::create_dir_all(
                path.parent()
                    .expect("every file in the manifest must have a parent"),
            )
            .unwrap_or_else(|err| {
                fatal!(
                    log,
                    "Failed to create parent directory for path {}: {}",
                    path.display(),
                    err
                )
            });
            if path.ends_with("state_file") {
                // cow memory files are special, ignore there creation here
                continue;
            }
            let f = std::fs::File::create(&path).unwrap_or_else(|err| {
                fatal!(log, "Failed to create file {}: {}", path.display(), err)
            });
            f.set_len(file_info.size_bytes).unwrap_or_else(|err| {
                fatal!(
                    log,
                    "Failed to truncate file {} to size {}: {}",
                    path.display(),
                    file_info.size_bytes,
                    err
                )
            });
        }
    }
pub ( crate ) fn preallocate_layout ( log : & ReplicaLogger , root : & Path , manifest : & Manifest ) { for file_info in manifest . file_table . iter ( ) { let path = root . join ( & file_info . relative_path ) ; std :: fs :: create_dir_all ( path . parent ( ) . expect ( " " ) , ) . unwrap_or_else ( | err | { fatal ! ( log " " path display ( ) err ) } ) ; if path . ends_with ( " " ) { // cow memory files are special, ignore there creation here continue ; } let f = std :: fs :: File :: create ( & path ) . unwrap_or_else ( | err | { fatal ! ( log " " path display ( ) err ) } ) ; f . set_len ( file_info . size_bytes ) . unwrap_or_else ( | err | { fatal ! ( log " " path display ( ) file_info size_bytes err ) } ) ; } }
Creates all the files listed in the manifest and resizes them to their
expected sizes.
Creates all the files listed in the manifest and resizes them to their expected sizes .
log
&ReplicaLogger
root
&Path
manifest
&Manifest