#include <stdlib.h>
#include <string.h>
#include <syslog.h>
-#include <wordexp.h>
#include <curl/curl.h>
#include <magic.h>
#include <pakfire/ctx.h>
#include <pakfire/logging.h>
#include <pakfire/os.h>
+#include <pakfire/path.h>
#include <pakfire/string.h>
struct pakfire_ctx {
}
int pakfire_ctx_set_cache_path(struct pakfire_ctx* ctx, const char* path) {
- wordexp_t result = {};
- int r;
-
- // Expand the path
- r = wordexp(path, &result, 0);
- if (r) {
- r = -EINVAL;
- goto ERROR;
- }
-
- // There should only be one result
- if (result.we_wordc != 1) {
- r = -EINVAL;
- goto ERROR;
- }
-
- // Store the result
- r = pakfire_string_set(ctx->paths.cache, result.we_wordv[0]);
- if (r)
- goto ERROR;
-
-ERROR:
- wordfree(&result);
-
- return r;
+ return pakfire_path_expand(ctx->paths.cache, path);
}
// Confirm
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
+#include <wordexp.h>
#include <pakfire/path.h>
#include <pakfire/string.h>
return __pakfire_string_set(dest, length, buffer);
}
+int __pakfire_path_expand(char* dest, const size_t length, const char* path) {
+ wordexp_t result = {};
+ int r;
+
+ // Expand the path
+ r = wordexp(path, &result, 0);
+ if (r) {
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // There should only be one result
+ if (result.we_wordc != 1) {
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Store the result
+ r = __pakfire_string_set(dest, length, result.we_wordv[0]);
+ if (r < 0)
+ goto ERROR;
+
+ERROR:
+ wordfree(&result);
+
+ return r;
+}
+
int pakfire_path_exists(const char* path) {
return !access(path, F_OK);
}
__pakfire_path_realpath(dest, sizeof(dest), path)
int __pakfire_path_realpath(char* dest, const size_t length, const char* path);
+#define pakfire_path_expand(dest, path) \
+ __pakfire_path_expand(dest, sizeof(dest), path)
+int __pakfire_path_expand(char* dest, const size_t length, const char* path);
+
int pakfire_path_exists(const char* path);
time_t pakfire_path_age(const char* path);