Utils: Let copyRecursively create target folder

Previously FileUtils::copyRecursively did create the target folder,
FilePath::copyRecursively now does the same.

If either src or target are .qrc paths, select the fallback copy
routine, as tar cannot read or write to a .qrc folder

see: 7cb74e325f for report about
failing test in testProject_multipleBuildConfigs

Change-Id: I52bb9ad8f018f359f598e5bc8b18ab31c901496f
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-01-26 07:16:49 +01:00
parent 1285b80c40
commit 94dd5a157b

View File

@@ -183,22 +183,31 @@ expected_str<void> copyRecursively_fallback(const FilePath &src, const FilePath
expected_str<void> DeviceFileAccess::copyRecursively(const FilePath &src, expected_str<void> DeviceFileAccess::copyRecursively(const FilePath &src,
const FilePath &target) const const FilePath &target) const
{ {
#ifdef UTILS_STATIC_LIBRARY if (!src.isDir()) {
return copyRecursively_fallback(src, target); return make_unexpected(Tr::tr("Cannot copy from %1, it is not a directory.")
#else .arg(src.toUserOutput())
if (!target.isWritableDir()) { .arg(target.toUserOutput()));
}
if (!target.ensureWritableDir()) {
return make_unexpected(Tr::tr("Cannot copy %1 to %2, it is not a writable directory.") return make_unexpected(Tr::tr("Cannot copy %1 to %2, it is not a writable directory.")
.arg(src.toUserOutput()) .arg(src.toUserOutput())
.arg(target.toUserOutput())); .arg(target.toUserOutput()));
} }
#ifdef UTILS_STATIC_LIBRARY
return copyRecursively_fallback(src, target);
#else
const FilePath tar = FilePath::fromString("tar").onDevice(target); const FilePath tar = FilePath::fromString("tar").onDevice(target);
const FilePath targetTar = tar.searchInPath(); const FilePath targetTar = tar.searchInPath();
const FilePath sTar = FilePath::fromString("tar").onDevice(src); const FilePath sTar = FilePath::fromString("tar").onDevice(src);
const FilePath sourceTar = sTar.searchInPath(); const FilePath sourceTar = sTar.searchInPath();
if (!targetTar.isExecutableFile() || !sourceTar.isExecutableFile()) const bool isSrcOrTargetQrc = src.toFSPathString().startsWith(":/")
|| target.toFSPathString().startsWith(":/");
if (isSrcOrTargetQrc || !targetTar.isExecutableFile() || !sourceTar.isExecutableFile())
return copyRecursively_fallback(src, target); return copyRecursively_fallback(src, target);
QtcProcess srcProcess; QtcProcess srcProcess;