Skip to content

Commit a3d7664

Browse files
committed
exmdb: move mkdir call in cu_cid_writeout
Perform the file check before going to create anything. On the off chance that another exmdb thread already created an attachment, this should save one syscall.
1 parent 0e0da1a commit a3d7664

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

exch/exmdb/common_util.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,11 +2992,6 @@ static errno_t cu_cid_writeout(const char *maildir, std::string_view data,
29922992
maildir = exmdb_server::get_dir();
29932993
path = maildir + "/cid/"s + hval.str();
29942994
cid = hval.str();
2995-
auto ret = gx_mkbasedir(path.c_str(), FMODE_PRIVATE);
2996-
if (ret < 0) {
2997-
mlog(LV_ERR, "E-2009: mkbasedir for %s: %s", path.c_str(), strerror(-ret));
2998-
return -ret;
2999-
}
30002995

30012996
/* See if the object already exists. (Skip compression.) */
30022997
wrapfd check_fd = open(path.c_str(), O_RDONLY);
@@ -3006,6 +3001,11 @@ static errno_t cu_cid_writeout(const char *maildir, std::string_view data,
30063001
return 0;
30073002
check_fd.close_rd();
30083003

3004+
auto ret = gx_mkbasedir(path.c_str(), FMODE_PRIVATE);
3005+
if (ret < 0) {
3006+
mlog(LV_ERR, "E-2009: mkbasedir for %s: %s", path.c_str(), strerror(-ret));
3007+
return -ret;
3008+
}
30093009
gromox::tmpfile tmf;
30103010
ret = tmf.open_linkable(maildir, O_RDWR | O_TRUNC);
30113011
if (ret < 0) {

0 commit comments

Comments
 (0)