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-unixfs
Commits
121dfb10
Commit
121dfb10
authored
Jan 22, 2015
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/commands: Fixed progress bar line clear race condition in 'add'
parent
2363cb63
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
65 deletions
+35
-65
core/commands/add.go
core/commands/add.go
+35
-65
No files found.
core/commands/add.go
View file @
121dfb10
package
commands
import
(
"bytes"
"errors"
"fmt"
"io"
...
...
@@ -108,9 +107,13 @@ remains to be implemented.
res
.
SetError
(
u
.
ErrCast
(),
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
nil
)
wrapperChan
:=
make
(
chan
interface
{})
res
.
SetOutput
((
<-
chan
interface
{})(
wrapperChan
))
quiet
,
_
,
err
:=
res
.
Request
()
.
Option
(
"quiet"
)
.
Bool
()
if
err
!=
nil
{
res
.
SetError
(
u
.
ErrCast
(),
cmds
.
ErrNormal
)
return
}
size
:=
int64
(
0
)
s
,
found
:=
res
.
Request
()
.
Values
()[
"size"
]
...
...
@@ -138,78 +141,45 @@ remains to be implemented.
bar
.
Update
()
}
go
func
()
{
lastFile
:=
""
var
totalProgress
,
prevFiles
,
lastBytes
int64
for
out
:=
range
outChan
{
output
:=
out
.
(
*
AddedObject
)
if
len
(
output
.
Hash
)
>
0
{
if
showProgressBar
{
// clear progress bar line before we print "added x" output
fmt
.
Fprintf
(
os
.
Stderr
,
"
\r
%s
\r
"
,
strings
.
Repeat
(
" "
,
terminalWidth
))
}
wrapperChan
<-
output
}
else
{
log
.
Debugf
(
"add progress: %v %v
\n
"
,
output
.
Name
,
output
.
Bytes
)
if
!
showProgressBar
{
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
)
}
lastFile
:=
""
var
totalProgress
,
prevFiles
,
lastBytes
int64
for
out
:=
range
outChan
{
output
:=
out
.
(
*
AddedObject
)
if
len
(
output
.
Hash
)
>
0
{
if
showProgressBar
{
bar
.
Update
()
// clear progress bar line before we print "added x" output
fmt
.
Fprintf
(
os
.
Stderr
,
"
\r
%s
\r
"
,
strings
.
Repeat
(
" "
,
terminalWidth
))
}
if
quiet
{
fmt
.
Printf
(
"%s
\n
"
,
output
.
Hash
)
}
else
{
fmt
.
Printf
(
"added %s %s
\n
"
,
output
.
Hash
,
output
.
Name
)
}
}
close
(
wrapperChan
)
}()
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
outChan
,
ok
:=
res
.
Output
()
.
(
<-
chan
interface
{})
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
quiet
,
_
,
err
:=
res
.
Request
()
.
Option
(
"quiet"
)
.
Bool
()
if
err
!=
nil
{
return
nil
,
err
}
}
else
{
log
.
Debugf
(
"add progress: %v %v
\n
"
,
output
.
Name
,
output
.
Bytes
)
marshal
:=
func
(
v
interface
{})
(
io
.
Reader
,
error
)
{
obj
,
ok
:=
v
.
(
*
AddedObject
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
if
!
showProgressBar
{
continue
}
var
buf
bytes
.
Buffer
if
quiet
{
buf
.
WriteString
(
fmt
.
Sprintf
(
"%s
\n
"
,
obj
.
Hash
))
}
else
{
buf
.
WriteString
(
fmt
.
Sprintf
(
"added %s %s
\n
"
,
obj
.
Hash
,
obj
.
Name
))
if
len
(
lastFile
)
==
0
{
lastFile
=
output
.
Name
}
if
output
.
Name
!=
lastFile
||
output
.
Bytes
<
lastBytes
{
prevFiles
+=
lastBytes
lastFile
=
output
.
Name
}
return
&
buf
,
nil
lastBytes
=
output
.
Bytes
delta
:=
prevFiles
+
lastBytes
-
totalProgress
totalProgress
=
bar
.
Add64
(
delta
)
}
return
&
cmds
.
ChannelMarshaler
{
Channel
:
outChan
,
Marshaler
:
marshal
,
},
nil
},
if
showProgressBar
{
bar
.
Update
()
}
}
},
Type
:
AddedObject
{},
}
...
...
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