Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix is_hardlink definition.
Vsevolod Stakhov committed 11 years ago
commit f27bcfa6ff434bf720e6b30ec832d30b4d6d64db
parent 31c55e0
4 files changed +22 -12
modified libpkg/pkg.c
@@ -1551,9 +1551,8 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
				}
			}

-
			/* special case for hardlinks */
			if (st.st_nlink > 1)
-
				regular = is_hardlink(hl, &st);
+
				regular = !is_hardlink(hl, &st);

			if (regular)
				flatsize += st.st_size;
@@ -1561,6 +1560,7 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
		if (strcmp(sha256, sum) != 0)
			pkgdb_file_set_cksum(db, f, sha256);
	}
+
	HASH_FREE(hl, free);

	pkg_get(pkg, PKG_FLATSIZE, &oldflatsize);
	if (flatsize != oldflatsize)
modified libpkg/pkg_create.c
@@ -84,7 +84,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		if (file->size == 0)
			file->size = (int64_t)st.st_size;

-
		if (!is_hardlink(hardlinks, &st)) {
+
		if (st.st_nlink == 1 || !is_hardlink(hardlinks, &st)) {
			flatsize += file->size;
		}

modified libpkg/pkg_ports.c
@@ -375,13 +375,23 @@ file(struct plist *p, char *line, struct file_attr *a)
			pkg_emit_error("Plist error, directory listed as a file: %s", line);
			free_file_attr(a);
			return (EPKG_FATAL);
-
		} else if (S_ISREG(st.st_mode))
-
			regular = true;
-

-

-
		/* special case for hardlinks */
-
		if (st.st_nlink > 1)
-
			regular = is_hardlink(p->hardlinks, &st);
+
		} else if (S_ISREG(st.st_mode)) {
+
			if (st.st_nlink > 1)
+
				regular = !is_hardlink(p->hardlinks, &st);
+
			else
+
				regular = true;
+

+
		} else if (S_ISLNK(st.st_mode)) {
+
			char linkbuf[MAXPATHLEN];
+
			int len;
+
			if ((len = readlink(testpath, linkbuf, sizeof(linkbuf))) == -1) {
+
				pkg_emit_errno("file", "readlink failed");
+
				return (EPKG_FATAL);
+
			}
+
			sha256_buf(linkbuf, len, sha256);
+
			buf = sha256;
+
			regular = false;
+
		}

		if (regular) {
			p->flatsize += st.st_size;
modified libpkg/utils.c
@@ -471,13 +471,13 @@ is_hardlink(struct hardlinks *hl, struct stat *st)

	HASH_FIND_INO(hl, &st->st_ino, h);
	if (h != NULL)
-
		return false;
+
		return (true);

	h = malloc(sizeof(struct hardlinks));
	h->inode = st->st_ino;
	HASH_ADD_INO(hl, inode, h);

-
	return (true);
+
	return (false);
}

bool