* Store the size of a store path in the database (to be precise, the
size of the NAR serialisation of the path, i.e., `nix-store --dump PATH'). This is useful for Hydra.
This commit is contained in:
		
							parent
							
								
									fb9368b5a0
								
							
						
					
					
						commit
						a3883cbd28
					
				
					 16 changed files with 144 additions and 91 deletions
				
			
		| 
						 | 
				
			
			@ -286,12 +286,14 @@ Hash hashFile(HashType ht, const Path & path)
 | 
			
		|||
HashSink::HashSink(HashType ht) : ht(ht)
 | 
			
		||||
{
 | 
			
		||||
    ctx = new Ctx;
 | 
			
		||||
    bytes = 0;
 | 
			
		||||
    start(ht, *ctx);
 | 
			
		||||
}
 | 
			
		||||
    
 | 
			
		||||
HashSink::HashSink(const HashSink & h)
 | 
			
		||||
{
 | 
			
		||||
    ht = h.ht;
 | 
			
		||||
    bytes = h.bytes;
 | 
			
		||||
    ctx = new Ctx;
 | 
			
		||||
    *ctx = *h.ctx;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -304,18 +306,20 @@ HashSink::~HashSink()
 | 
			
		|||
void HashSink::operator ()
 | 
			
		||||
    (const unsigned char * data, unsigned int len)
 | 
			
		||||
{
 | 
			
		||||
    bytes += len;
 | 
			
		||||
    update(ht, *ctx, data, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Hash HashSink::finish()
 | 
			
		||||
HashResult HashSink::finish()
 | 
			
		||||
{
 | 
			
		||||
    Hash hash(ht);
 | 
			
		||||
    nix::finish(ht, *ctx, hash.hash);
 | 
			
		||||
    return hash;
 | 
			
		||||
    return HashResult(hash, bytes);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Hash hashPath(HashType ht, const Path & path, PathFilter & filter)
 | 
			
		||||
HashResult hashPath(
 | 
			
		||||
    HashType ht, const Path & path, PathFilter & filter)
 | 
			
		||||
{
 | 
			
		||||
    HashSink sink(ht);
 | 
			
		||||
    dumpPath(path, sink, filter);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,7 +40,6 @@ struct Hash
 | 
			
		|||
 | 
			
		||||
    /* For sorting. */
 | 
			
		||||
    bool operator < (const Hash & h) const;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +71,8 @@ Hash hashFile(HashType ht, const Path & path);
 | 
			
		|||
   (essentially) hashString(ht, dumpPath(path)). */
 | 
			
		||||
struct PathFilter;
 | 
			
		||||
extern PathFilter defaultPathFilter;
 | 
			
		||||
Hash hashPath(HashType ht, const Path & path,
 | 
			
		||||
typedef std::pair<Hash, unsigned long long> HashResult;
 | 
			
		||||
HashResult hashPath(HashType ht, const Path & path,
 | 
			
		||||
    PathFilter & filter = defaultPathFilter);
 | 
			
		||||
 | 
			
		||||
/* Compress a hash to the specified number of bytes by cyclically
 | 
			
		||||
| 
						 | 
				
			
			@ -93,13 +93,14 @@ class HashSink : public Sink
 | 
			
		|||
private:
 | 
			
		||||
    HashType ht;
 | 
			
		||||
    Ctx * ctx;
 | 
			
		||||
    unsigned long long bytes;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    HashSink(HashType ht);
 | 
			
		||||
    HashSink(const HashSink & h);
 | 
			
		||||
    ~HashSink();
 | 
			
		||||
    virtual void operator () (const unsigned char * data, unsigned int len);
 | 
			
		||||
    Hash finish();
 | 
			
		||||
    HashResult finish();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue