package: prevent creating a package that contains itself.

Fixes #10117.

Change-Id: I4be59189a47dd0ad400fe46786d7058be4ed6d3f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2778
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Adrien Destugues 2020-05-22 19:19:52 +02:00 committed by waddlesplash
parent 984492f14a
commit 82817fee45
1 changed files with 13 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include <unistd.h>
#include <Entry.h>
#include <Path.h>
#include <package/PackageInfo.h>
#include <package/hpkg/HPKGDefs.h>
@ -120,6 +121,18 @@ command_create(int argc, const char* const* argv)
return 1;
}
BPath outputPath(packageFileName, NULL, true);
BPath inputPath(changeToDirectory, NULL, true);
BPath parent;
while (outputPath.GetParent(&parent) == B_OK) {
if (outputPath == inputPath) {
fprintf(stderr, "Error: output package can't be in the same "
"directory as input files.");
return 1;
}
outputPath = parent;
}
// create package
BPackageWriterParameters writerParameters;
writerParameters.SetCompressionLevel(compressionLevel);