[sheepdog] [PATCH v2 4/6] farm: add sha1_file_exist() to sha1_file.c

Kai Zhang kyle at zelin.io
Sat Jun 8 04:02:31 CEST 2013


Signed-off-by: Kai Zhang <kyle at zelin.io>
---
 collie/farm/farm.h      |    1 +
 collie/farm/sha1_file.c |    5 +++++
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/collie/farm/farm.h b/collie/farm/farm.h
index 5a81987..58f7335 100644
--- a/collie/farm/farm.h
+++ b/collie/farm/farm.h
@@ -61,6 +61,7 @@ void *snap_log_read(int *out_nr);
 int snap_log_write(uint32_t idx, const char *tag, unsigned char *sha1);
 
 /* sha1_file.c */
+bool sha1_file_exist(const unsigned char *sha1);
 int sha1_file_write(unsigned char *buf, size_t len, unsigned char *sha1);
 void *sha1_file_read(const unsigned char *sha1, size_t *size);
 int get_sha1_hex(const char *hex, unsigned char *sha1);
diff --git a/collie/farm/sha1_file.c b/collie/farm/sha1_file.c
index 6543f32..7fd0bd7 100644
--- a/collie/farm/sha1_file.c
+++ b/collie/farm/sha1_file.c
@@ -150,6 +150,11 @@ err_open:
 	return ret;
 }
 
+bool sha1_file_exist(const unsigned char *sha1)
+{
+	return (access(sha1_to_path(sha1), R_OK) == 0);
+}
+
 int sha1_file_write(unsigned char *buf, size_t len, unsigned char *outsha1)
 {
 	unsigned char sha1[SHA1_LEN];
-- 
1.7.1




More information about the sheepdog mailing list