mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-04 21:47:46 +03:00
Add sync_dir()
This commit is contained in:
parent
9a77c5369c
commit
a2903c80cd
@ -194,3 +194,35 @@ int is_empty_dir(const char *dir)
|
||||
|
||||
return dirent ? 0 : 1;
|
||||
}
|
||||
|
||||
void sync_dir(const char *file)
|
||||
{
|
||||
int fd;
|
||||
char *dir, *c;
|
||||
|
||||
if (!(dir = dbg_strdup(file))) {
|
||||
log_error("sync_dir failed in strdup");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dir_exists(dir)) {
|
||||
c = dir + strlen(dir);
|
||||
while (*c != '/' && c > dir)
|
||||
c--;
|
||||
|
||||
*c = '\0';
|
||||
}
|
||||
|
||||
if ((fd = open(dir, O_RDONLY)) == -1) {
|
||||
log_sys_error("open", dir);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (fsync(fd) == -1)
|
||||
log_sys_error("fsync", dir);
|
||||
|
||||
close(fd);
|
||||
|
||||
out:
|
||||
dbg_free(dir);
|
||||
}
|
||||
|
@ -32,3 +32,6 @@ int is_empty_dir(const char *dir);
|
||||
* if directory was successfully created (or already exists), else 0.
|
||||
*/
|
||||
int create_dir(const char *dir);
|
||||
|
||||
/* Sync directory changes */
|
||||
void sync_dir(const char *file);
|
||||
|
Loading…
x
Reference in New Issue
Block a user