1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-28 02:50:41 +03:00

Silently remove any existing symlink before creating a new one.

This commit is contained in:
Alasdair Kergon 2002-01-22 19:58:37 +00:00
parent b9dc2b7ea2
commit 58f323bc80
2 changed files with 16 additions and 3 deletions

View File

@ -30,7 +30,7 @@ static int _mk_dir(struct volume_group *vg)
if (!build_vg_path(vg_path, sizeof(vg_path),
vg->cmd->dev_dir, vg->name)) {
log_err("Couldn't create volume group directory.");
log_error("Couldn't construct name of volume group directory.");
return 0;
}
@ -59,6 +59,7 @@ static int _rm_dir(struct volume_group *vg)
static int _mk_link(struct logical_volume *lv)
{
char lv_path[PATH_MAX], link_path[PATH_MAX];
struct stat buf;
if (!build_dm_path(lv_path, sizeof(lv_path), lv->vg->name, lv->name)) {
log_err("Couldn't create destination path for "
@ -74,6 +75,18 @@ static int _mk_link(struct logical_volume *lv)
return 0;
}
if (!lstat(link_path, &buf)) {
if (!S_ISLNK(buf.st_mode)) {
log_error("Symbolic link %s not created: file exists",
link_path);
return 0;
}
if (unlink(link_path) < 0) {
log_sys_error("unlink", link_path);
return 0;
}
}
log_very_verbose("Linking %s to %s", link_path, lv_path);
if (symlink(lv_path, link_path) < 0) {
log_sys_error("symlink", link_path);

View File

@ -97,8 +97,8 @@ void vgchange_available(struct volume_group *vg)
log_verbose("Deactivated %d logical volumes in "
"volume group %s", lv_open, vg->name);
log_print("Volume group %s updated", vg->name);
log_print("%d logical volume(s) in volume group %s now active",
lvs_in_vg_activated(vg), vg->name);
return;
}