mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Checks for directory existence before creating them.
This commit is contained in:
parent
4ec6ac113c
commit
030a70fcd3
2 changed files with 16 additions and 8 deletions
6
HISTORY
6
HISTORY
|
|
@ -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
18
util.c
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue