return rootDir;
}
-void rpmtsSetRootDir(rpmts ts, const char * rootDir)
+int rpmtsSetRootDir(rpmts ts, const char * rootDir)
{
- if (ts != NULL) {
- ts->rootDir = _free(ts->rootDir);
+ if (ts == NULL || (rootDir && rootDir[0] != '/')) {
+ return -1;
+ }
- /* Ensure clean path with a trailing slash */
- ts->rootDir = rootDir ? rpmGetPath(rootDir, NULL) : xstrdup("/");
- if (strcmp(ts->rootDir, "/") != 0) {
- rstrcat(&ts->rootDir, "/");
- }
+ ts->rootDir = _free(ts->rootDir);
+ /* Ensure clean path with a trailing slash */
+ ts->rootDir = rootDir ? rpmGetPath(rootDir, NULL) : xstrdup("/");
+ if (strcmp(ts->rootDir, "/") != 0) {
+ rstrcat(&ts->rootDir, "/");
}
+ return 0;
}
const char * rpmtsCurrDir(rpmts ts)
/** \ingroup rpmts
* Set transaction rootDir, i.e. path to chroot(2).
- * @todo disallow funky http:// etc urls...
* @param ts transaction set
* @param rootDir new transaction rootDir (or NULL)
+ * @return 0 on success, -1 on error (invalid rootDir)
*/
-void rpmtsSetRootDir(rpmts ts, const char * rootDir);
+int rpmtsSetRootDir(rpmts ts, const char * rootDir);
/** \ingroup rpmts
* Get transaction currDir, i.e. current directory before chroot(2).