Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
094cfd72
Commit
094cfd72
authored
Jan 05, 2017
by
David Ashpole
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed wc zombie goroutine issue
parent
13780bba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
26 deletions
+19
-26
fs.go
pkg/volume/util/fs.go
+19
-26
No files found.
pkg/volume/util/fs.go
View file @
094cfd72
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"bytes"
"bytes"
"fmt"
"fmt"
"os/exec"
"os/exec"
"strconv"
"strings"
"strings"
"syscall"
"syscall"
...
@@ -69,35 +68,29 @@ func Du(path string) (*resource.Quantity, error) {
...
@@ -69,35 +68,29 @@ func Du(path string) (*resource.Quantity, error) {
return
&
used
,
nil
return
&
used
,
nil
}
}
// Find uses the command `find <path> -dev -printf '.' | wc -c` to count files and directories.
// Find uses the
equivalent of the
command `find <path> -dev -printf '.' | wc -c` to count files and directories.
// While this is not an exact measure of inodes used, it is a very good approximation.
// While this is not an exact measure of inodes used, it is a very good approximation.
func
Find
(
path
string
)
(
int64
,
error
)
{
func
Find
(
path
string
)
(
int64
,
error
)
{
var
stdout
,
stdwcerr
,
stdfinderr
bytes
.
Buffer
if
path
==
""
{
var
err
error
return
0
,
fmt
.
Errorf
(
"invalid directory"
)
}
var
counter
byteCounter
var
stderr
bytes
.
Buffer
findCmd
:=
exec
.
Command
(
"find"
,
path
,
"-xdev"
,
"-printf"
,
"."
)
findCmd
:=
exec
.
Command
(
"find"
,
path
,
"-xdev"
,
"-printf"
,
"."
)
wcCmd
:=
exec
.
Command
(
"wc"
,
"-c"
)
findCmd
.
Stdout
,
findCmd
.
Stderr
=
&
counter
,
&
stderr
if
wcCmd
.
Stdin
,
err
=
findCmd
.
StdoutPipe
();
err
!=
nil
{
if
err
:=
findCmd
.
Start
();
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"failed to
setup stdout for cmd %v - %v"
,
findCmd
.
Args
,
err
)
return
0
,
fmt
.
Errorf
(
"failed to
exec cmd %v - %v; stderr: %v"
,
findCmd
.
Args
,
err
,
stderr
.
String
()
)
}
}
wcCmd
.
Stdout
,
wcCmd
.
Stderr
,
findCmd
.
Stderr
=
&
stdout
,
&
stdwcerr
,
&
stdfinderr
if
err
:=
findCmd
.
Wait
();
err
!=
nil
{
if
err
=
findCmd
.
Start
();
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"cmd %v failed. stderr: %s; err: %v"
,
findCmd
.
Args
,
stderr
.
String
(),
err
)
return
0
,
fmt
.
Errorf
(
"failed to exec cmd %v - %v; stderr: %v"
,
findCmd
.
Args
,
err
,
stdfinderr
.
String
())
}
}
return
counter
.
bytesWritten
,
nil
}
if
err
=
wcCmd
.
Start
();
err
!=
nil
{
// Simple io.Writer implementation that counts how many bytes were written.
return
0
,
fmt
.
Errorf
(
"failed to exec cmd %v - %v; stderr %v"
,
wcCmd
.
Args
,
err
,
stdwcerr
.
String
())
type
byteCounter
struct
{
bytesWritten
int64
}
}
err
=
findCmd
.
Wait
()
func
(
b
*
byteCounter
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
if
err
!=
nil
{
b
.
bytesWritten
+=
int64
(
len
(
p
))
return
0
,
fmt
.
Errorf
(
"cmd %v failed. stderr: %s; err: %v"
,
findCmd
.
Args
,
stdfinderr
.
String
(),
err
)
return
len
(
p
),
nil
}
err
=
wcCmd
.
Wait
()
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"cmd %v failed. stderr: %s; err: %v"
,
wcCmd
.
Args
,
stdwcerr
.
String
(),
err
)
}
inodeUsage
,
err
:=
strconv
.
ParseInt
(
strings
.
TrimSpace
(
stdout
.
String
()),
10
,
64
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"cannot parse cmds: %v, %v output %s - %s"
,
findCmd
.
Args
,
wcCmd
.
Args
,
stdout
.
String
(),
err
)
}
return
inodeUsage
,
nil
}
}
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