Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
fix renaming error
Browse files Browse the repository at this point in the history
  • Loading branch information
celestix committed Jul 10, 2023
1 parent 7685213 commit 33ac388
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ This document contains the list of things which might be added to the library in
2.) Handle documents with unknown content length.

3.) Add support for resuming downloads. (DONE)

4.) Fix downloads for different disk drives:
warp: rename C:\Users\...\AppData\Roaming/warp/dldata/0dce3722/warp.dl D:\../100MB.bin: The system cannot move the file to a different disk drive.
12 changes: 8 additions & 4 deletions dloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ func (d *Downloader) Start() (err error) {
if err != nil {
return
}
defer d.f.Close()
defer func() {
d.f.Close()
err = os.Rename(d.fName, d.GetSavePath())
}()
d.Log("Starting download...")
d.ohmap.Make()
partSize, rpartSize := d.getPartSize()
Expand All @@ -236,7 +239,6 @@ func (d *Downloader) Start() (err error) {
d.wg.Wait()
d.handlers.DownloadCompleteHandler(MAIN_HASH, d.contentLength.v())
d.Log("All segments downloaded!")
err = os.Rename(d.fName, d.GetSavePath())
return
}

Expand All @@ -252,7 +254,10 @@ func (d *Downloader) Resume(parts map[int64]*ItemPart) (err error) {
if err != nil {
return
}
defer d.f.Close()
defer func() {
d.f.Close()
err = os.Rename(d.fName, d.GetSavePath())
}()
d.Log("Resuming download...")
d.ohmap.Make()
espeed := 4 * MB / int64(len(parts))
Expand All @@ -267,7 +272,6 @@ func (d *Downloader) Resume(parts map[int64]*ItemPart) (err error) {
d.wg.Wait()
d.handlers.DownloadCompleteHandler(MAIN_HASH, d.contentLength.v())
d.Log("All segments downloaded!")
err = os.Rename(d.fName, d.GetSavePath())
return
}

Expand Down

0 comments on commit 33ac388

Please sign in to comment.