mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-08-28 16:05:15 +00:00
read file path as list of subdirs
This commit is contained in:
@@ -128,6 +128,18 @@ namespace torrents
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::pair<std::vector<std::string_view>, size_t> ParseStringList (std::string_view buf)
|
||||
{
|
||||
std::vector<std::string_view> strings;
|
||||
size_t len = ParseList (buf, [&strings](std::string_view str)->size_t
|
||||
{
|
||||
auto [s, l] = ExtractByteString (str);
|
||||
if (l) strings.push_back (s);
|
||||
return l;
|
||||
});
|
||||
return { strings, len };
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
Piece::Piece (size_t size, const uint8_t * hash):
|
||||
@@ -298,8 +310,6 @@ namespace torrents
|
||||
}
|
||||
else if (key == "info")
|
||||
return ParseInfo (buf);
|
||||
else if (key == "files")
|
||||
return ParseFiles (buf);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
@@ -347,6 +357,8 @@ namespace torrents
|
||||
m_Pieces.reserve (m_Length/m_PieceLength + 1);
|
||||
return ParsePieces (buf);
|
||||
}
|
||||
else if (key == "files")
|
||||
return ParseFiles (buf);
|
||||
return 0;
|
||||
});
|
||||
if (!len) return 0;
|
||||
@@ -364,8 +376,8 @@ namespace torrents
|
||||
{
|
||||
if (key == "path")
|
||||
{
|
||||
auto [path, l] = ExtractByteString (value);
|
||||
if (l) filePath = path;
|
||||
auto [subdirs, l] = ParseStringList (value);
|
||||
if (l) filePath = i2p::fs::CreatePath (subdirs);
|
||||
return l;
|
||||
}
|
||||
else if (key == "length")
|
||||
@@ -1215,6 +1227,12 @@ namespace torrents
|
||||
delete[] buf;
|
||||
if (!torrent->GetFiles ().empty ())
|
||||
{
|
||||
for (auto [filePath, fileLength]: torrent->GetFiles ())
|
||||
{
|
||||
auto partFilePath = GetTorrentFilePath (torrent->GetName (), filePath + ".part");
|
||||
if (!i2p::fs::Exists (partFilePath))
|
||||
i2p::fs::CreateAndReserveFile (partFilePath, fileLength);
|
||||
}
|
||||
LogPrint (eLogError, "Torrents: Multi-file torrent ", path);
|
||||
return;
|
||||
}
|
||||
@@ -1411,6 +1429,14 @@ namespace torrents
|
||||
return s.str ();
|
||||
}
|
||||
|
||||
std::string TorrentsTunnel::GetTorrentFilePath (const std::string& subdir, const std::string& filename) const
|
||||
{
|
||||
std::stringstream s("");
|
||||
s << m_TorrentsDir;
|
||||
i2p::fs::_ExpandPath(s, subdir, filename);
|
||||
return s.str ();
|
||||
}
|
||||
|
||||
void TorrentsTunnel::ScheduleTrackerRequestsCheck ()
|
||||
{
|
||||
m_TrackerRequestsCheckTimer.expires_after (std::chrono::milliseconds(TRACKER_REQUESTS_CHECK_TIMEOUT));
|
||||
|
||||
@@ -281,6 +281,7 @@ namespace torrents
|
||||
|
||||
const std::string& GetPeerID () const { return m_PeerID; }
|
||||
std::string GetTorrentFilePath (const std::string& filename) const;
|
||||
std::string GetTorrentFilePath (const std::string& subdir, const std::string& filename) const;
|
||||
std::shared_ptr<Torrent> FindTorrent (const Torrent::InfoHash& infoHash) const;
|
||||
std::list<std::shared_ptr<PeerConnection> > GetTorrentConnections (std::shared_ptr<Torrent> torrent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user