# #
#############################################################################*/
-#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/limits.h>
time_t time_created;
PakfirePackage pkg;
+ char filename[PATH_MAX];
// Reader
struct archive* reader;
}
PAKFIRE_EXPORT const char* pakfire_packager_filename(struct pakfire_packager* packager) {
- return pakfire_package_get_filename(packager->pkg);
+ if (!*packager->filename) {
+ const char* filename = pakfire_package_get_filename(packager->pkg);
+
+ // Add arch
+ if (pakfire_package_is_source(packager->pkg))
+ pakfire_string_set(packager->filename, filename);
+ else {
+ const char* arch = pakfire_package_get_arch(packager->pkg);
+
+ pakfire_string_format(packager->filename, "%s/%s", arch, filename);
+ }
+ }
+
+ return packager->filename;
}
static int pakfire_packager_copy_data(struct pakfire_packager* packager,
goto ERROR;
}
- // Write the payload
+ // Write checksums
r = pakfire_packager_write_archive(packager, a, NULL, PAKFIRE_ARCHIVE_FN_CHECKSUMS,
&mtree, fmtree);
if (r) {
PAKFIRE_EXPORT int pakfire_packager_finish_to_directory(struct pakfire_packager* packager,
const char* target) {
- DIR* d = NULL;
char path[PATH_MAX];
+ char tmppath[PATH_MAX];
int r = 1;
// target cannot be empty
return 1;
}
+ // Get the filename of the package
+ const char* filename = pakfire_packager_filename(packager);
+ if (!filename) {
+ ERROR(packager->pakfire, "Could not generate filename for package: %s\n",
+ strerror(errno));
+ r = 1;
+ goto ERROR;
+ }
+
+ // Make the package path
+ r = pakfire_string_format(path, "%s/%s", target, filename);
+ if (r < 0)
+ goto ERROR;
+
+ // Create the parent directory
+ r = pakfire_mkparentdir(path, 0);
+ if (r)
+ goto ERROR;
+
// Create a temporary file in the target directory
- pakfire_string_format(path, "%s/.pakfire-package.XXXXXX", target);
+ r = pakfire_string_format(tmppath, "%s.XXXXXX", path);
+ if (r < 0)
+ goto ERROR;
// Create a temporary result file
- FILE* f = pakfire_mktemp(path);
+ FILE* f = pakfire_mktemp(tmppath);
if (!f)
goto ERROR;
// Write the finished package
r = pakfire_packager_finish(packager, f);
+ fclose(f);
+
if (r) {
ERROR(packager->pakfire, "pakfire_packager_finish() failed: %s\n",
strerror(errno));
goto ERROR;
}
- // Close the file
- fclose(f);
- f = NULL;
-
- // Get the filename of the package
- const char* filename = pakfire_packager_filename(packager);
- if (!filename) {
- r = 1;
- goto ERROR;
- }
-
- // Open the target directory
- d = opendir(target);
- if (!d) {
- r = 1;
- goto ERROR;
- }
-
// Move the temporary file to destination
- r = renameat(AT_FDCWD, path, dirfd(d), filename);
- if (r)
+ r = rename(tmppath, path);
+ if (r) {
+ ERROR(packager->pakfire, "Could not move %s to %s: %s\n",
+ tmppath, path, strerror(errno));
goto ERROR;
+ }
- DEBUG(packager->pakfire, "Package written to %s/%s\n", target, filename);
+ INFO(packager->pakfire, "Package written to %s\n", path);
// Success
r = 0;
ERROR:
// Remove temporary file
- if (r && *path)
- unlink(path);
- if (f)
- fclose(f);
- if (d)
- closedir(d);
+ if (r && *tmppath)
+ unlink(tmppath);
- return 0;
+ return r;
}
PAKFIRE_EXPORT int pakfire_packager_add(struct pakfire_packager* packager,