PyErr_SetString(PyExc_ValueError, "Invalid architecture");
break;
+ // path does not exist
+ case -ENOENT:
+ PyErr_Format(PyExc_FileNotFoundError,
+ "%s does not exist or is not a directory", path);
+ break;
+
// Anything else
default:
PyErr_SetNone(PyExc_OSError);
char* pakfire_path_join(const char* first, const char* second);
const char* pakfire_path_relpath(const char* root, const char* path);
+int pakfire_path_isdir(const char* path);
char* pakfire_basename(const char* path);
char* pakfire_dirname(const char* path);
pakfire_free;
pakfire_get_errno;
pakfire_partition_string;
+ pakfire_path_isdir;
pakfire_path_join;
pakfire_path_relpath;
pakfire_read_file_into_buffer;
return NULL;
}
+ // Check if path exists
+ if (!pakfire_path_isdir(path)) {
+ errno = -ENOENT;
+ return NULL;
+ }
+
Pakfire pakfire = pakfire_calloc(1, sizeof(*pakfire));
if (pakfire) {
pakfire->nrefs = 1;
return NULL;
}
+PAKFIRE_EXPORT int pakfire_path_isdir(const char* path) {
+ struct stat s;
+
+ if (stat(path, &s) != 0) {
+ // Does not seem to exist
+ return 0;
+ }
+
+ if (S_ISDIR(s.st_mode))
+ return 1;
+
+ return 0;
+}
+
PAKFIRE_EXPORT char* pakfire_basename(const char* path) {
char* name = pakfire_strdup(path);