Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
coreospackage
Commits
66b49239
Commit
66b49239
authored
7 years ago
by
Rahul A. Sutar
Browse files
Options
Downloads
Patches
Plain Diff
Fixed download helper bug
1) Modified fileutil.go to return a status message. 2) Removed all log.fatal
parent
4cda9273
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!18
Fixed download helper bug
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
downloadhelper/fileutil.go
+15
-14
downloadhelper/fileutil.go
with
15 additions
and
14 deletions
downloadhelper/fileutil.go
+
15
−
14
View file @
66b49239
...
...
@@ -6,7 +6,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
...
...
@@ -16,13 +16,13 @@ import (
func
createTempFile
(
partFilename
string
,
fileBegin
,
fileEnd
int
)
{
buf
:=
new
(
bytes
.
Buffer
)
if
err
:=
binary
.
Write
(
buf
,
binary
.
LittleEndian
,
int64
(
fileBegin
));
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
if
err
:=
binary
.
Write
(
buf
,
binary
.
LittleEndian
,
int64
(
fileEnd
));
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
if
err
:=
ioutil
.
WriteFile
(
partFilename
,
buf
.
Bytes
(),
0666
);
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
}
...
...
@@ -47,7 +47,7 @@ func writeBytes(partFilename string, reader []byte, byteStart, byteEnd int) erro
func
readHeader
(
partFilename
string
)
(
int
,
int
)
{
reader
,
err
:=
ioutil
.
ReadFile
(
partFilename
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
header
:=
reader
[
:
16
]
byteStart
:=
int
(
binary
.
LittleEndian
.
Uint64
(
header
[
0
:
8
]))
+
len
(
reader
)
-
16
...
...
@@ -63,20 +63,20 @@ func mergeFiles(filename string, count int) {
file
,
err
:=
os
.
OpenFile
(
DownloadLocation
+
"/"
+
tempFilename
,
os
.
O_CREATE
|
os
.
O_WRONLY
|
os
.
O_APPEND
,
0666
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
defer
file
.
Close
()
for
i
:=
0
;
i
<
count
;
i
++
{
partFilename
:=
DownloadLocation
+
"/temp/"
+
filename
+
"_"
+
strconv
.
Itoa
(
i
)
reader
,
err
:=
ioutil
.
ReadFile
(
partFilename
)
reader
=
reader
[
16
:
]
if
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
if
_
,
err
=
file
.
WriteString
(
string
(
reader
));
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
}
file
.
Close
()
...
...
@@ -102,7 +102,7 @@ func clearFiles(filename string, count int) {
}
empty
,
err
:=
isDirEmpty
(
DownloadLocation
+
"/temp/"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
if
empty
{
os
.
Remove
(
DownloadLocation
+
"/temp/"
)
...
...
@@ -112,20 +112,21 @@ func clearFiles(filename string, count int) {
func
noOfExistingConnection
(
filename
string
,
length
int
)
int
{
existingFilename
:=
DownloadLocation
+
"/temp/"
+
filename
+
"_0"
if
_
,
err
:=
os
.
Stat
(
existingFilename
);
err
!=
nil
{
log
.
Fatal
(
"No file to resume downloading"
)
return
0
// panic("No file to resume downloading 1")
}
if
_
,
err
:=
os
.
Stat
(
existingFilename
);
err
==
nil
{
reader
,
err
:=
ioutil
.
ReadFile
(
existingFilename
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
panic
(
err
)
}
if
len
(
reader
)
<
16
{
log
.
Fatal
(
"No file to resume downloading"
)
panic
(
"No file to resume downloading
2
"
)
}
header
:=
reader
[
:
16
]
interval
:=
int
(
binary
.
LittleEndian
.
Uint64
(
header
[
8
:
16
]))
-
int
(
binary
.
LittleEndian
.
Uint64
(
header
[
0
:
8
]))
if
interval
==
0
{
log
.
Fatal
(
"No file to resume downloading"
)
panic
(
"No file to resume downloading
3
"
)
}
return
(
length
/
interval
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets