Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
4fdfbc7d
Commit
4fdfbc7d
authored
Dec 04, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compute add size in background to not stall add operation
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
dc2e343a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
43 deletions
+61
-43
core/commands/add.go
core/commands/add.go
+61
-43
No files found.
core/commands/add.go
View file @
4fdfbc7d
...
@@ -65,14 +65,19 @@ remains to be implemented.
...
@@ -65,14 +65,19 @@ remains to be implemented.
return
nil
return
nil
}
}
size
,
err
:=
sizeFile
.
Size
()
sizeCh
:=
make
(
chan
int64
,
1
)
if
err
!=
nil
{
req
.
Values
()[
"size"
]
=
sizeCh
// see comment above
return
nil
}
log
.
Debugf
(
"Total size of file being added: %v
\n
"
,
size
)
go
func
()
{
req
.
Values
()[
"size"
]
=
size
size
,
err
:=
sizeFile
.
Size
()
if
err
!=
nil
{
// see comment above
return
}
log
.
Debugf
(
"Total size of file being added: %v
\n
"
,
size
)
sizeCh
<-
size
}()
return
nil
return
nil
},
},
...
@@ -189,17 +194,12 @@ remains to be implemented.
...
@@ -189,17 +194,12 @@ remains to be implemented.
return
return
}
}
size
:=
int64
(
0
)
showProgressBar
:=
!
quiet
s
,
found
:=
req
.
Values
()[
"size"
]
if
found
{
size
=
s
.
(
int64
)
}
showProgressBar
:=
!
quiet
&&
size
>=
progressBarMinSize
var
bar
*
pb
.
ProgressBar
var
bar
*
pb
.
ProgressBar
var
terminalWidth
int
var
terminalWidth
int
if
showProgressBar
{
if
showProgressBar
{
bar
=
pb
.
New64
(
size
)
.
SetUnits
(
pb
.
U_BYTES
)
bar
=
pb
.
New64
(
0
)
.
SetUnits
(
pb
.
U_BYTES
)
bar
.
ManualUpdate
=
true
bar
.
ManualUpdate
=
true
bar
.
Start
()
bar
.
Start
()
...
@@ -215,43 +215,61 @@ remains to be implemented.
...
@@ -215,43 +215,61 @@ remains to be implemented.
bar
.
Update
()
bar
.
Update
()
}
}
var
sizeChan
chan
int64
s
,
found
:=
req
.
Values
()[
"size"
]
if
found
{
sizeChan
=
s
.
(
chan
int64
)
}
lastFile
:=
""
lastFile
:=
""
var
totalProgress
,
prevFiles
,
lastBytes
int64
var
totalProgress
,
prevFiles
,
lastBytes
int64
for
out
:=
range
outChan
{
LOOP
:
output
:=
out
.
(
*
coreunix
.
AddedObject
)
for
{
if
len
(
output
.
Hash
)
>
0
{
select
{
if
showProgressBar
{
case
out
,
ok
:=
<-
outChan
:
// clear progress bar line before we print "added x" output
if
!
ok
{
fmt
.
Fprintf
(
res
.
Stderr
(),
"
\0
33[2K
\r
"
)
break
LOOP
}
if
quiet
{
fmt
.
Fprintf
(
res
.
Stdout
(),
"%s
\n
"
,
output
.
Hash
)
}
else
{
fmt
.
Fprintf
(
res
.
Stdout
(),
"added %s %s
\n
"
,
output
.
Hash
,
output
.
Name
)
}
}
output
:=
out
.
(
*
coreunix
.
AddedObject
)
if
len
(
output
.
Hash
)
>
0
{
if
showProgressBar
{
// clear progress bar line before we print "added x" output
fmt
.
Fprintf
(
res
.
Stderr
(),
"
\0
33[2K
\r
"
)
}
if
quiet
{
fmt
.
Fprintf
(
res
.
Stdout
(),
"%s
\n
"
,
output
.
Hash
)
}
else
{
fmt
.
Fprintf
(
res
.
Stdout
(),
"added %s %s
\n
"
,
output
.
Hash
,
output
.
Name
)
}
}
else
{
}
else
{
log
.
Debugf
(
"add progress: %v %v
\n
"
,
output
.
Name
,
output
.
Bytes
)
log
.
Debugf
(
"add progress: %v %v
\n
"
,
output
.
Name
,
output
.
Bytes
)
if
!
showProgressBar
{
if
!
showProgressBar
{
continue
continue
}
if
len
(
lastFile
)
==
0
{
lastFile
=
output
.
Name
}
if
output
.
Name
!=
lastFile
||
output
.
Bytes
<
lastBytes
{
prevFiles
+=
lastBytes
lastFile
=
output
.
Name
}
lastBytes
=
output
.
Bytes
delta
:=
prevFiles
+
lastBytes
-
totalProgress
totalProgress
=
bar
.
Add64
(
delta
)
}
}
if
len
(
lastFile
)
==
0
{
if
showProgressBar
{
lastFile
=
output
.
Name
bar
.
Update
()
}
if
output
.
Name
!=
lastFile
||
output
.
Bytes
<
lastBytes
{
prevFiles
+=
lastBytes
lastFile
=
output
.
Name
}
}
lastBytes
=
output
.
Bytes
case
size
:=
<-
sizeChan
:
delta
:=
prevFiles
+
lastBytes
-
totalProgress
bar
.
Total
=
size
totalProgress
=
bar
.
Add64
(
delta
)
bar
.
ShowPercent
=
true
}
bar
.
ShowBar
=
true
bar
.
ShowTimeLeft
=
true
if
showProgressBar
{
bar
.
Update
()
}
}
}
}
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment