mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
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:
parent
b678f5f286
commit
1042d6d3df
@ -84,4 +84,19 @@ impl Blobstore for Fileblob {
|
|||||||
})
|
})
|
||||||
.boxify()
|
.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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user