-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Don't save incomplete downloaded files #258
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,7 +289,7 @@ protected virtual async Task<bool> DownloadBinaryPostAsync(TumblrPost downloadIt | |
string fileName = FileName(downloadItem); | ||
UpdateProgressQueueInformation(Resources.ProgressSkipFile, fileName); | ||
} | ||
else if (!shellService.Settings.LoadAllDatabases && blog.CheckDirectoryForFiles && (blog.CheckIfBlogShouldCheckDirectory(FileNameUrl(downloadItem), FileNameNew(downloadItem)) | ||
/*else if (!shellService.Settings.LoadAllDatabases && blog.CheckDirectoryForFiles && (blog.CheckIfBlogShouldCheckDirectory(FileNameUrl(downloadItem), FileNameNew(downloadItem)) | ||
|| blog.CheckIfBlogShouldCheckDirectory(FileName(downloadItem), FileNameNew(downloadItem)))) | ||
{ | ||
string fileName = AddFileToDb(downloadItem); | ||
|
@@ -299,7 +299,7 @@ protected virtual async Task<bool> DownloadBinaryPostAsync(TumblrPost downloadIt | |
{ | ||
string fileName = AddFileToDb(downloadItem); | ||
UpdateProgressQueueInformation(Resources.ProgressSkipFile, fileName); | ||
} | ||
}*/ | ||
else | ||
{ | ||
string blogDownloadLocation = blog.DownloadLocation(); | ||
|
@@ -310,6 +310,7 @@ protected virtual async Task<bool> DownloadBinaryPostAsync(TumblrPost downloadIt | |
UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); | ||
if (!await DownloadBinaryFileAsync(fileLocation, fileLocationUrlList, Url(downloadItem))) | ||
{ | ||
RemoveFileFromDb(FileNameUrl(downloadItem)); // TODO: Temp plan, the addition should happen only when the download is successful. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That could be a way to do it. But keep in mind that AddFileToDb is called early, because this url shall not be downloaded from another thread while this one is still working on it, and it also determines the final filename in case of using filename templates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment, I have no better way to improve/staticize the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understood that it's a draft and work in progress (WIP). Everything is ok, I only wanted to give more information as input. |
||
return false; | ||
} | ||
|
||
|
@@ -352,6 +353,10 @@ protected string AddFileToDb(TumblrPost downloadItem) | |
} | ||
return files.AddFileToDb(FileNameUrl(downloadItem), downloadItem.Filename, AppendTemplate); | ||
} | ||
protected void RemoveFileFromDb(string fileNameUrl) | ||
{ | ||
files.RemoveFileFromDb(fileNameUrl); | ||
} | ||
|
||
public bool CheckIfFileExistsInDB(string filenameUrl) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ public async Task<bool> DownloadFileWithResumeAsync(string url, string destinati | |
|
||
if (ct.IsCancellationRequested) return false; | ||
|
||
var fileMode = totalBytesReceived > 0 ? FileMode.Append : FileMode.Create; | ||
var fileMode = File.Exists(destinationPath) ? FileMode.Append : FileMode.Create; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's another (unnecessary) filesystem access. But besides that I just see an error and an optimization possibility in the previous block (old code). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the previous code is working fine for a created file of 0 bytes. Testcase may be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I was unclear, I meant the lines 41-54 of the old code (not your changes). |
||
|
||
var fileStream = new FileStream(destinationPath, fileMode, FileAccess.Write, FileShare.Read, bufferSize, true); | ||
try | ||
|
@@ -131,6 +131,8 @@ public async Task<bool> DownloadFileWithResumeAsync(string url, string destinati | |
} | ||
else | ||
{ | ||
fileStream?.Dispose(); | ||
File.Delete(destinationPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not delete the file in all cases. What about a video download that timeouts short before the end? It prevents resume functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strangely enough, as of now, I don't see resume to be working, probably due to skipping any existing files in filesystem or DB (index). |
||
throw; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you removing functionality here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invisible options are a hidden danger. I removed it to reduce testing noise since it
AddFileToDb
, this should probably be reverted but needs to be retested/rewritten.