fix: copy fileName before calling std::distance

This commit is contained in:
siddhantCodes 2024-05-13 15:36:00 +05:30
parent 1db7d1b840
commit 4d0777ca69

View File

@ -22,11 +22,12 @@ void builtinUnpackChannel(
unpackTarfile(src, out);
auto entries = std::filesystem::directory_iterator{out};
auto file_count = std::distance(entries, std::filesystem::directory_iterator{});
auto fileName = entries->path().string();
auto fileCount = std::distance(std::filesystem::begin(entries), std::filesystem::end(entries));
if (file_count != 1)
if (fileCount != 1)
throw Error("channel tarball '%s' contains more than one file", src);
renameFile(entries->path().string(), (out + "/" + channelName));
renameFile(fileName, (out + "/" + channelName));
}
}