Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Completly finish the ability to save untracked files
Baptiste Daroussin committed 6 years ago
commit 88eb0b221f7de9907d512723f7621ac698e3bf82
parent bbdeecd
4 files changed +37 -9
modified libpkg/pkg_add.c
@@ -645,7 +645,6 @@ do_extract(struct archive *a, struct archive_entry *ae,
		return (EPKG_OK);

	pkg_emit_extract_begin(pkg);
-
	pkg_open_root_fd(pkg);
	pkg_emit_progress_start(NULL);

	do {
@@ -719,7 +718,7 @@ cleanup:
}

static int
-
pkg_extract_finalize(struct pkgdb *db, struct pkg *pkg)
+
pkg_extract_finalize(struct pkg *pkg)
{
	struct stat st;
	struct pkg_file *f = NULL;
@@ -753,7 +752,8 @@ pkg_extract_finalize(struct pkgdb *db, struct pkg *pkg)
		 * results in renameat returning 0 of the from file is hardlink
		 * on the to file, but the to file is not removed
		 */
-
		if (fstatat(pkg->rootfd, RELATIVE_PATH(fto), &st,
+
		if (f->previous != PKG_FILE_NONE &&
+
		    fstatat(pkg->rootfd, RELATIVE_PATH(fto), &st,
		    AT_SYMLINK_NOFOLLOW) != -1) {
#ifdef HAVE_CHFLAGSAT
			if (!install_as_user && st.st_flags & NOCHANGESFLAGS) {
@@ -762,7 +762,7 @@ pkg_extract_finalize(struct pkgdb *db, struct pkg *pkg)
			}
#endif
			/* if the files does not belong to any package, we do save it */
-
			if (pkgdb_file_exists(db, fto)) {
+
			if (f->previous == PKG_FILE_SAVE) {
				snprintf(path, sizeof(path), "%s.pkgsave", f->path);
				renameat(pkg->rootfd, RELATIVE_PATH(fto),
				    pkg->rootfd, RELATIVE_PATH(path));
@@ -1024,6 +1024,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	struct pkg		*pkg = NULL;
	UT_string		*message;
	struct pkg_message	*msg;
+
	struct pkg_file		*f;
	const char		*msgstr;
	bool			 extract = true;
	int			 retcode = EPKG_OK;
@@ -1095,6 +1096,18 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	if (reloc != NULL)
		pkg_kv_add(&pkg->annotations, "relocated", reloc, "annotation");

+
	pkg_open_root_fd(pkg);
+
	/* analyse previous files */
+
	f = NULL;
+
	while (pkg_files(pkg, &f) == EPKG_OK) {
+
		if (faccessat(pkg->rootfd, RELATIVE_PATH(f->path), F_OK, 0) == 0) {
+
			f->previous = PKG_FILE_EXIST;
+
			if (!pkgdb_file_exists(db, f->path)) {
+
				f->previous = PKG_FILE_SAVE;
+
			}
+
		}
+
	}
+

	/* register the package before installing it in case there are
	 * problems that could be caught here. */
	retcode = pkgdb_register_pkg(db, pkg,
@@ -1145,7 +1158,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	/* Update configuration file content with db with newer versions */
	pkgdb_update_config_file_content(pkg, db->sqlite);

-
	retcode = pkg_extract_finalize(db, pkg);
+
	retcode = pkg_extract_finalize(pkg);
cleanup_reg:
	pkgdb_register_finale(db, retcode);
	/*
@@ -1258,7 +1271,7 @@ pkg_add_upgrade(struct pkgdb *db, const char *path, unsigned flags,
}

int
-
pkg_add_fromdir(struct pkgdb *db, struct pkg *pkg, const char *src)
+
pkg_add_fromdir(struct pkg *pkg, const char *src)
{
	struct stat st;
	struct pkg_dir *d = NULL;
@@ -1428,7 +1441,7 @@ pkg_add_fromdir(struct pkgdb *db, struct pkg *pkg, const char *src)
		}
	}

-
	retcode = pkg_extract_finalize(db, pkg);
+
	retcode = pkg_extract_finalize(pkg);

cleanup:
	kh_destroy_hls(hardlinks);
modified libpkg/pkgdb_query.c
@@ -187,8 +187,9 @@ pkgdb_file_exists(struct pkgdb *db, const char *path)

	sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT);

-
	if (sqlite3_step(stmt) != SQLITE_DONE)
+
	if (sqlite3_step(stmt) != SQLITE_DONE) {
		ret = true;
+
	}

	sqlite3_finalize(stmt);
	return (ret);
modified libpkg/private/pkg.h
@@ -342,6 +342,12 @@ struct pkg_dep {
};

typedef enum {
+
	PKG_FILE_NONE = 0,
+
	PKG_FILE_EXIST,
+
	PKG_FILE_SAVE,
+
} file_previous_t;
+

+
typedef enum {
	PKG_MESSAGE_ALWAYS = 0,
	PKG_MESSAGE_INSTALL,
	PKG_MESSAGE_REMOVE,
@@ -403,6 +409,7 @@ struct pkg_file {
	struct pkg_config_file *config;
	struct timespec	 time[2];
	struct pkg_file	*next, *prev;
+
	file_previous_t	 previous;
};

struct pkg_dir {
@@ -852,7 +859,7 @@ enum pkg_metalog_type {
int pkg_set_from_fileat(int fd, struct pkg *pkg, pkg_attr attr, const char *file, bool trimcr);
void pkg_rollback_cb(void *);
void pkg_rollback_pkg(struct pkg *);
-
int pkg_add_fromdir(struct pkgdb *, struct pkg *, const char *);
+
int pkg_add_fromdir(struct pkg *, const char *);
struct pkg_dep* pkg_adddep_chain(struct pkg_dep *chain,
		struct pkg *pkg, const char *name, const char *origin, const
		char *version, bool locked);
modified tests/frontend/conflicts.sh
@@ -190,6 +190,13 @@ fileexists_notinpkg_body()
		pkg -o REPOS_DIR=${TMPDIR} -r ${TMPDIR}/target install -qy test

	test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave || atf_fail "file not saved when it should have"
+

+
	# Test the nominal situation just in case
+
	rm -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave
+
	atf_check \
+
		pkg -o REPOS_DIR=${TMPDIR} -r ${TMPDIR}/target install -qyf test
+
	test -f ${TMPDIR}/target/${TMPDIR}/a.pkgsave && atf_fail "file saved when it should not have"
+
	return 0
}

find_conflicts_body() {