From b419f3d7cbea3361d489d1a4dddc4e6b1f932916 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 22 Apr 2011 10:33:21 -0700 Subject: [PATCH] filestore: lfn_unlink removes the entry as last step so that if it crashes in the middle of operation we're not left with a hole in the list of objects. In case of a crash, recovery should fix any stale objects. Also it is currently assumed that we're currently the only users and there are no concurrent operations. --- src/os/FileStore.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 4d8dc65c6445c..6753c3f3b2769 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -445,11 +445,6 @@ static int lfn_unlink(const char *pathname) return -1; } - err = unlink(short_fn); - if (err < 0) - return err; - - path_len = filename - pathname; memcpy(short_fn2, pathname, path_len); @@ -460,9 +455,12 @@ static int lfn_unlink(const char *pathname) build_filename(&short_fn2[path_len], sizeof(short_fn2) - path_len, filename, i); ret = stat(short_fn2, &buf); if (ret < 0) { - if (i == r + 1) + if (i == r + 1) { + err = unlink(short_fn); + if (err < 0) + return err; return 0; - + } break; } } -- 2.39.5