linfdisk: cleanup fsync usage

* always use fsync() if the device open read-write
 * use sync() on demand

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2014-09-17 12:54:05 +02:00
parent 2e73a998f4
commit 2aeff7618e
1 changed files with 5 additions and 4 deletions

View File

@ -455,9 +455,8 @@ int fdisk_deassign_device(struct fdisk_context *cxt, int nosync)
assert(cxt);
assert(cxt->dev_fd >= 0);
if (cxt->readonly || nosync)
if (cxt->readonly)
close(cxt->dev_fd);
else {
if (fsync(cxt->dev_fd) || close(cxt->dev_fd)) {
fdisk_warn(cxt, _("%s: close device failed"),
@ -465,8 +464,10 @@ int fdisk_deassign_device(struct fdisk_context *cxt, int nosync)
return -errno;
}
fdisk_info(cxt, _("Syncing disks."));
sync();
if (!nosync) {
fdisk_info(cxt, _("Syncing disks."));
sync();
}
}
free(cxt->dev_path);