Checks for directory existence before creating them.

This commit is contained in:
Andrea Mazzoleni 2013-12-15 10:01:07 +01:00
parent 4ec6ac113c
commit 030a70fcd3
2 changed files with 16 additions and 8 deletions

View file

@ -6,8 +6,10 @@ SnapRAID HISTORY
* If a disk changes UUID, automatically disable the inode
recognition, because this is likely a new filesystem with
all the inodes reassigned, and we don't want to risk a false
positive when searching for inode.
* Does not count empty dirs as files in the diff counters.
positive when searching for inode/timestamp/size.
* Allow to run a fix command with disks that doesn't needs to be
fixed mounted as read-only.
* Doesn't count empty dirs as files in the diff counters.
5.1 2013/12
===========

18
util.c
View file

@ -1235,6 +1235,7 @@ int pathcmp(const char* a, const char* b)
int mkancestor(const char* file)
{
char dir[PATH_MAX];
struct stat st;
char* c;
pathcpy(dir, sizeof(dir), file);
@ -1262,12 +1263,17 @@ int mkancestor(const char* file)
}
#endif
/* try creating it */
if (mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0) {
/* just created */
return 0;
}
if (errno == EEXIST) {
/*
* Check if the dir already exists using lstat().
*
* Note that in Windows when dealing with read-only media
* you cannot try to create the directory, and expecting
* the EEXIST error because the call will fail with ERROR_WRITE_PROTECTED.
*
* Also in Windows it's better to use lstat() than stat() because it
* doen't need to open the dir with CreateFile().
*/
if (lstat(dir, &st) == 0) {
/* it already exists */
return 0;
}