pub fn from_folder(pkg: &PackageId, path: DirLock, location: DirectRes) -> Res<Self> {
        let mf_path = path.path().join("elba.toml");

        let file = fs::File::open(mf_path).context(format_err!(
            "package {} at {} is missing manifest",
            pkg,
            path.path().display()
        ))?;
        let mut file = BufReader::new(file);
        let mut contents = String::new();
        file.read_to_string(&mut contents)?;

        if let Some(x) = Manifest::workspace(&contents) {
            if let Some(p) = x.get(pkg.name()) {
                let lock = DirLock::acquire(&path.path().join(&p.0))?;
                // We immediately release our lock on the parent folder
                drop(path);
                return Source::from_folder(pkg, lock, location);
            }
        }

        let manifest = Manifest::from_str(&contents)?;

        if manifest.name() != pkg.name() {
            bail!(
                "names don't match: {} was declared, but {} was found in elba.toml",
                pkg.name(),
                manifest.name()
            )
        }

        // Creating the hash
        let walker = WalkDir::new(path.path())
            .into_iter()
            .filter_entry(|entry| {
                entry.file_name() != "target" && entry
                    .file_name()
                    .to_str()
                    .map(|s| !s.starts_with('.'))
                    .unwrap_or(false)
            }).filter(|e| e.as_ref().unwrap().file_type().is_file());

        let mut hash = Sha256::new();
        for f in walker {
            let mut file = fs::File::open(f.unwrap().path())?;
            let fh = Sha256::digest_reader(&mut file)?;
            hash.input(&fh);
        }
        let hash = hexify_hash(hash.result().as_slice());

        Ok(Source {
            inner: Arc::new(SourceInner {
                meta: manifest,
                res: pkg.resolution().clone(),
                location,
                path,
                hash,
            }),
        })
    }
/// Creates a Source from a folder on disk.
///
/// The purpose of having a hash is for builds. The resolution graph only stores Summaries. If we were
/// to rely solely on hashing the Summaries of a package's dependencies to determine if we need
/// to rebuild a package, we'd run into a big problem: a package would only get rebuilt iff its
/// own version changed or a version of one of its dependents changed. This is a problem for
/// DirectRes deps, since they can change often without changing their version, leading to
/// erroneous cases where packages aren't rebuilt. Even if we were to use the hash that
/// determines the folder name of a package, it wouldn't be enough. Local dependencies' folder
/// names never change and don't have a hash, and git repos which pin themselves to a branch
/// can maintain the same hash while updating their contents.
///
/// Not only that, but stray ibc files and other miscellaneous crap could get into the source
/// directory, which would force us to rebuild yet again.
///
/// To remedy this, we'd like to have a hash that indicates that the file contents of a Source
/// have changed.
///
/// Note that the hash stored differs from the hash used to determine if a package needs to be
/// redownloaded completely; for git repos, if the resolution is to use master, then the same
/// folder will be used, but will be checked out to the latest master every time.
Creates a Source from a folder on disk.
The purpose of having a hash is for builds. The resolution graph only stores Summaries. If we were
to rely solely on hashing the Summaries of a package's dependencies to determine if we need
to rebuild a package, we'd run into a big problem: a package would only get rebuilt iff its
own version changed or a version of one of its dependents changed. This is a problem for
DirectRes deps, since they can change often without changing their version, leading to
erroneous cases where packages aren't rebuilt. Even if we were to use the hash that
determines the folder name of a package, it wouldn't be enough. Local dependencies' folder
names never change and don't have a hash, and git repos which pin themselves to a branch
can maintain the same hash while updating their contents.

Not only that, but stray ibc files and other miscellaneous crap could get into the source
directory, which would force us to rebuild yet again.

To remedy this, we'd like to have a hash that indicates that the file contents of a Source
have changed.

Note that the hash stored differs from the hash used to determine if a package needs to be
redownloaded completely; for git repos, if the resolution is to use master, then the same
folder will be used, but will be checked out to the latest master every time.
Creates a Source from a folder on disk . The purpose of having a hash is for builds . The resolution graph only stores Summaries . If we were to rely solely on hashing the Summaries of a package ' s dependencies to determine if we need to rebuild a package we ' d run into a big problem : a package would only get rebuilt iff its own version changed or a version of one of its dependents changed . This is a problem for DirectRes deps since they can change often without changing their version leading to erroneous cases where packages aren ' t rebuilt . Even if we were to use the hash that determines the folder name of a package it wouldn ' t be enough . Local dependencies ' folder names never change and don ' t have a hash and git repos which pin themselves to a branch can maintain the same hash while updating their contents . Not only that but stray ibc files and other miscellaneous crap could get into the source directory which would force us to rebuild yet again . To remedy this we ' d like to have a hash that indicates that the file contents of a Source have changed . Note that the hash stored differs from the hash used to determine if a package needs to be redownloaded completely ; for git repos if the resolution is to use master then the same folder will be used but will be checked out to the latest master every time .
pub fn from_folder(pkg: &PackageId, path: DirLock, location: DirectRes) -> Res<Self> {
        let mf_path = path.path().join("elba.toml");
        let file = fs::File::open(mf_path).context(format_err!(
            "package {} at {} is missing manifest",
            pkg,
            path.path().display()
        ))?;
        let mut file = BufReader::new(file);
        let mut contents = String::new();
        file.read_to_string(&mut contents)?;
        if let Some(x) = Manifest::workspace(&contents) {
            if let Some(p) = x.get(pkg.name()) {
                let lock = DirLock::acquire(&path.path().join(&p.0))?;
                // We immediately release our lock on the parent folder
                drop(path);
                return Source::from_folder(pkg, lock, location);
            }
        }
        let manifest = Manifest::from_str(&contents)?;
        if manifest.name() != pkg.name() {
            bail!(
                "names don't match: {} was declared, but {} was found in elba.toml",
                pkg.name(),
                manifest.name()
            )
        }
        // Creating the hash
        let walker = WalkDir::new(path.path())
            .into_iter()
            .filter_entry(|entry| {
                entry.file_name() != "target" && entry
                    .file_name()
                    .to_str()
                    .map(|s| !s.starts_with('.'))
                    .unwrap_or(false)
            }).filter(|e| e.as_ref().unwrap().file_type().is_file());
        let mut hash = Sha256::new();
        for f in walker {
            let mut file = fs::File::open(f.unwrap().path())?;
            let fh = Sha256::digest_reader(&mut file)?;
            hash.input(&fh);
        }
        let hash = hexify_hash(hash.result().as_slice());
        Ok(Source {
            inner: Arc::new(SourceInner {
                meta: manifest,
                res: pkg.resolution().clone(),
                location,
                path,
                hash,
            }),
        })
    }
pub fn from_folder ( pkg : & PackageId , path : DirLock , location : DirectRes ) -> Res < Self > { let mf_path = path . path ( ) . join ( " " ) ; let file = fs :: File :: open ( mf_path ) . context ( format_err ! ( " " pkg path path ( ) display ( ) ) ) ? ; let mut file = BufReader :: new ( file ) ; let mut contents = String :: new ( ) ; file . read_to_string ( & mut contents ) ? ; if let Some ( x ) = Manifest :: workspace ( & contents ) { if let Some ( p ) = x . get ( pkg . name ( ) ) { let lock = DirLock :: acquire ( & path . path ( ) . join ( & p . 0 ) ) ? ; // We immediately release our lock on the parent folder drop ( path ) ; return Source :: from_folder ( pkg , lock , location ) ; } } let manifest = Manifest :: from_str ( & contents ) ? ; if manifest . name ( ) != pkg . name ( ) { bail ! ( " " pkg name ( ) manifest name ( ) ) } // Creating the hash let walker = WalkDir :: new ( path . path ( ) ) . into_iter ( ) . filter_entry ( | entry | { entry . file_name ( ) != " " && entry . file_name ( ) . to_str ( ) . map ( | s | ! s . starts_with ( '.' ) ) . unwrap_or ( false ) } ) . filter ( | e | e . as_ref ( ) . unwrap ( ) . file_type ( ) . is_file ( ) ) ; let mut hash = Sha256 :: new ( ) ; for f in walker { let mut file = fs :: File :: open ( f . unwrap ( ) . path ( ) ) ? ; let fh = Sha256 :: digest_reader ( & mut file ) ? ; hash . input ( & fh ) ; } let hash = hexify_hash ( hash . result ( ) . as_slice ( ) ) ; Ok ( Source { inner : Arc :: new ( SourceInner { meta : manifest , res : pkg . resolution ( ) . clone ( ) , location , path , hash , } ) , } ) }
Creates a Source from a folder on disk.
Creates a Source from a folder on disk .
pkg
&PackageId
path
DirLock
location
DirectRes