Skip to content

Commit 3b637d4

Browse files
committed
fix: solve copy telegram session
1 parent 6be482f commit 3b637d4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

TelegramDownloader/Data/TelegramService.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,23 @@ private void newClient()
9595
var downloadSessionPath = UserService.USERDATAFOLDER + "/WTelegram_download.session";
9696

9797
// Copy the main session file if download session doesn't exist
98+
// Use FileShare.ReadWrite to allow reading while the main client has it open
9899
if (!File.Exists(downloadSessionPath) && File.Exists(mainSessionPath))
99100
{
100-
File.Copy(mainSessionPath, downloadSessionPath, overwrite: true);
101-
_logger.LogInformation("Created download client session from main session");
101+
try
102+
{
103+
// Read with FileShare.ReadWrite to avoid locking conflicts
104+
using (var sourceStream = new FileStream(mainSessionPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
105+
using (var destStream = new FileStream(downloadSessionPath, FileMode.Create, FileAccess.Write, FileShare.None))
106+
{
107+
await sourceStream.CopyToAsync(destStream);
108+
}
109+
_logger.LogInformation("Created download client session from main session");
110+
}
111+
catch (Exception copyEx)
112+
{
113+
_logger.LogWarning(copyEx, "Could not copy session file, download client will create new session");
114+
}
102115
}
103116

104117
downloadClient = new WTelegram.Client(

0 commit comments

Comments
 (0)