int pkg_dest_init(pkg_dest_t * dest, const char *name, const char *root_dir) { char *status_file_dir; dest->name = xstrdup(name); /* Guarantee that dest->root_dir ends with a '/' */ if (root_dir[strlen(root_dir) - 1] == '/') { dest->root_dir = xstrdup(root_dir); } else { sprintf_alloc(&dest->root_dir, "%s/", root_dir); } file_mkdir_hier(dest->root_dir, 0755); sprintf_alloc(&dest->info_dir, "%s/%s", dest->root_dir, opkg_config->info_dir); file_mkdir_hier(dest->info_dir, 0755); sprintf_alloc(&dest->status_file_name, "%s/%s", dest->root_dir, opkg_config->status_file); /* Ensure that the directory in which we will create the status file exists. */ status_file_dir = xdirname(dest->status_file_name); file_mkdir_hier(status_file_dir, 0755); free(status_file_dir); return 0; }
int file_mkdir_hier(const char *path, long mode) { struct stat st; int r; r = stat(path, &st); if (r < 0 && errno == ENOENT) { int status; char *parent; parent = xdirname(path); status = file_mkdir_hier(parent, mode | 0300); free(parent); if (status < 0) return -1; r = mkdir(path, 0777); if (r < 0) { opkg_perror(ERROR, "Cannot create directory `%s'", path); return -1; } if (mode != -1) { r = chmod(path, mode); if (r < 0) { opkg_perror(ERROR, "Cannot set permissions of directory `%s'", path); return -1; } } } return 0; }
int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir, ipkg_conf_t *conf) { dest->name = strdup(name); /* Guarantee that dest->root_dir ends with a '/' */ if (str_ends_with(root_dir, "/")) { dest->root_dir = strdup(root_dir); } else { sprintf_alloc(&dest->root_dir, "%s/", root_dir); } file_mkdir_hier(dest->root_dir, 0755); if (!conf->ipkg_libdir) { sprintf_alloc(&dest->ipkg_dir, "%s%s", dest->root_dir, IPKG_STATE_DIR_PREFIX); }else{ sprintf_alloc(&dest->ipkg_dir, "%s%s", dest->root_dir, conf->ipkg_libdir); } file_mkdir_hier(dest->ipkg_dir, 0755); if (str_starts_with (lists_dir, "/")) sprintf_alloc(&dest->lists_dir, "%s", lists_dir); else sprintf_alloc(&dest->lists_dir, "/%s", lists_dir); file_mkdir_hier(dest->lists_dir, 0755); sprintf_alloc(&dest->info_dir, "%s/%s", dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX); file_mkdir_hier(dest->info_dir, 0755); sprintf_alloc(&dest->status_file_name, "%s/%s", dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX); sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp", dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX); dest->status_file = NULL; return 0; }