Fix bug in torrent file not enforcing order to final manifests.
Change-Id: I8ee6243a8e25b305db719fa16b5e653f12ef9cdc
diff --git a/src/torrent-file.cpp b/src/torrent-file.cpp
index dafeb41..d7918d2 100644
--- a/src/torrent-file.cpp
+++ b/src/torrent-file.cpp
@@ -257,15 +257,17 @@
Name torrentName(commonPrefix.toUri() + "/torrent-file");
TorrentFile currentTorrentFile(torrentName, commonPrefix, {});
std::vector<std::pair<std::vector<FileManifest>, std::vector<Data>>> manifestPairs;
-
+ // sort all the file names lexicographically
+ std::set<std::string> fileNames;
+ for (auto i = directoryPtr; i != fs::recursive_directory_iterator(); ++i) {
+ fileNames.insert(i->path().string());
+ }
size_t manifestFileCounter = 0u;
- for (fs::recursive_directory_iterator i = directoryPtr;
- i != fs::recursive_directory_iterator();
- ++i) {
+ for (const auto& fileName : fileNames) {
Name manifestPrefix("/NTORRENT" +
directoryPathName.getSubName(directoryPathName.size() - 1).toUri());
std::pair<std::vector<FileManifest>, std::vector<Data>> currentManifestPair =
- FileManifest::generate((*i).path().string(),
+ FileManifest::generate(fileName,
manifestPrefix, subManifestSize,
dataPacketSize, returnData);