Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
When pkg add fails and we try to clean up what we may have installed already, be silent about failures doing so (since things may not have been installed actually).
Gerald Pfeifer committed 12 years ago
commit d55f151d8bd5f589ac85110f7e1f304da16ee6d3
parent fcd3ca3
3 files changed +12 -6
modified libpkg/pkg_add.c
@@ -316,8 +316,8 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_
	 * Extract the files on disk.
	 */
	if (extract && (retcode = do_extract(a, ae)) != EPKG_OK) {
-
		/* If the add failed, clean up */
-
		pkg_delete_files(pkg, 1);
+
		/* If the add failed, clean up (silently) */
+
		pkg_delete_files(pkg, 2);
		pkg_delete_dirs(db, pkg, 1);
		goto cleanup_reg;
	}
modified libpkg/pkg_delete.c
@@ -107,7 +107,8 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)
		}
	}

-
	if ((ret = pkg_delete_files(pkg, flags & PKG_DELETE_FORCE)) != EPKG_OK)
+
	if ((ret = pkg_delete_files(pkg, flags & PKG_DELETE_FORCE ? 1 : 0))
+
            != EPKG_OK)
		return (ret);

	if ((flags & (PKG_DELETE_NOSCRIPT | PKG_DELETE_UPGRADE)) == 0) {
@@ -129,7 +130,11 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)
}

int
-
pkg_delete_files(struct pkg *pkg, bool force)
+
pkg_delete_files(struct pkg *pkg, unsigned force)
+
	/* force: 0 ... be careful and vocal about it. 
+
	 *        1 ... remove files without bothering about checksums.
+
	 *        2 ... like 1, but remain silent if removal fails.
+
	 */
{
	struct pkg_file	*file = NULL;
	char		 sha256[SHA256_DIGEST_LENGTH * 2 + 1];
@@ -156,7 +161,8 @@ pkg_delete_files(struct pkg *pkg, bool force)
		}

		if (unlink(path) == -1) {
-
			pkg_emit_errno("unlink", path);
+
			if (force < 2)
+
				pkg_emit_errno("unlink", path);
			continue;
		}
	}
modified libpkg/private/pkg.h
@@ -362,7 +362,7 @@ int packing_append_tree(struct packing *pack, const char *treepath,
int packing_finish(struct packing *pack);
pkg_formats packing_format_from_string(const char *str);

-
int pkg_delete_files(struct pkg *pkg, bool force);
+
int pkg_delete_files(struct pkg *pkg, unsigned force);
int pkg_delete_dirs(struct pkgdb *db, struct pkg *pkg, bool force);

int pkgdb_is_dir_used(struct pkgdb *db, const char *dir, int64_t *res);