#define _XOPEN_SOURCE 500
+#include <glib/gstdio.h>
#include <glib.h>
#include <arpa/inet.h>
#include <assert.h>
return FALSE;
}
+
+gboolean
+cr_identical_files(const gchar *fn1,
+ const gchar *fn2,
+ gboolean *identical,
+ GError **err)
+{
+ int rc;
+ GStatBuf buf1, buf2;
+
+ *identical = FALSE;
+
+ // Stat old file
+ rc = g_stat(fn1, &buf1);
+ if (rc == -1) {
+ if (errno == ENOENT) // The first file doesn't exist
+ return TRUE;
+
+ g_set_error(err, CREATEREPO_C_ERROR, CRE_IO,
+ "Cannot stat %s: %s", fn1, g_strerror(errno));
+ return FALSE;
+ }
+
+ // Stat new file
+ rc = g_stat(fn2, &buf2);
+ if (rc == -1) {
+ if (errno == ENOENT) // The second file doesn't exist
+ return TRUE;
+
+ g_set_error(err, CREATEREPO_C_ERROR, CRE_IO,
+ "Cannot stat %s: %s", fn2, g_strerror(errno));
+ return FALSE;
+ }
+
+ // Check if both paths point to the same file
+ if (buf1.st_ino == buf2.st_ino)
+ *identical = TRUE;
+
+ return TRUE;
+}
+
void
cr_nevra_free(cr_NEVRA *nevra);
+/** Are the files identical?
+ * Different paths could point to the same file.
+ * This functions checks if both paths point to the same file or not.
+ * If one of the files doesn't exists, the funcion doesn't fail
+ * and just put FALSE into "indentical" value and returns.
+ * @param fn1 First path
+ * @param fn2 Second path
+ * @param identical Are the files same or not
+ * @param err GError **
+ * @return FALSE if an error was encountered, TRUE otherwise
+ */
+gboolean
+cr_identical_files(const gchar *fn1,
+ const gchar *fn2,
+ gboolean *identical,
+ GError **err);
+
/** @} */
#ifdef __cplusplus