mononoke: blobstore: optimize is_present()

Summary:
This patch adds optimized implementations of is_present() for FileBlob (which
we use in tests), and ManifoldBlob (which AFAIK, we don't use: I believe we use
ManifoldThriftBlob instead).

The underlying goal is to make sure we don't perform accidental reads of LFS
blobs when all we meant was to check a blob existed when committing a
changeset.

For ManifoldBlob, this is implemented by querying for an empty range, which
appears to be explicitly supported as per the Rust client's source code (it
sets `?withPayload=0` as a query parameter).

Reviewed By: StanislavGlebik

Differential Revision: D16262273

fbshipit-source-id: c055f63d114d40be2c448b8c8e34eb82d0e641b5
This commit is contained in:
Thomas Orozco 2019-07-15 10:26:35 -07:00 committed by Facebook Github Bot
parent b678f5f286
commit 1042d6d3df

View File

@ -84,4 +84,19 @@ impl Blobstore for Fileblob {
})
.boxify()
}
fn is_present(&self, _ctx: CoreContext, key: String) -> BoxFuture<bool, Error> {
let p = self.path(&key);
poll_fn(move || {
let ret = match File::open(&p) {
Err(ref e) if e.kind() == io::ErrorKind::NotFound => false,
Err(e) => return Err(e),
Ok(_) => true,
};
Ok(Async::Ready(ret))
})
.from_err()
.boxify()
}
}