Skip to content

Commit ab89e63

Browse files
estespthaJeztah
authored andcommitted
Move isFifo from process/io to sys/ and make public
Make "IsFifo" a public function for use by other parts of containerd codebase. Signed-off-by: Phil Estes <[email protected]> (cherry picked from commit 0c78dac) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 62b6623 commit ab89e63

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

pkg/process/io.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/containerd/containerd/log"
3434
"github.com/containerd/containerd/namespaces"
3535
"github.com/containerd/containerd/pkg/stdio"
36+
"github.com/containerd/containerd/sys"
3637
"github.com/containerd/fifo"
3738
runc "github.com/containerd/go-runc"
3839
"github.com/pkg/errors"
@@ -174,7 +175,7 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w
174175
},
175176
},
176177
} {
177-
ok, err := isFifo(i.name)
178+
ok, err := sys.IsFifo(i.name)
178179
if err != nil {
179180
return err
180181
}
@@ -240,22 +241,6 @@ func (c *countingWriteCloser) Close() error {
240241
return c.WriteCloser.Close()
241242
}
242243

243-
// isFifo checks if a file is a fifo
244-
// if the file does not exist then it returns false
245-
func isFifo(path string) (bool, error) {
246-
stat, err := os.Stat(path)
247-
if err != nil {
248-
if os.IsNotExist(err) {
249-
return false, nil
250-
}
251-
return false, err
252-
}
253-
if stat.Mode()&os.ModeNamedPipe == os.ModeNamedPipe {
254-
return true, nil
255-
}
256-
return false, nil
257-
}
258-
259244
// NewBinaryIO runs a custom binary process for pluggable shim logging
260245
func NewBinaryIO(ctx context.Context, id string, uri *url.URL) (runc.IO, error) {
261246
ns, err := namespaces.NamespaceRequired(ctx)

sys/filesys.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package sys
18+
19+
import "os"
20+
21+
// IsFifo checks if a file is a (named pipe) fifo
22+
// if the file does not exist then it returns false
23+
func IsFifo(path string) (bool, error) {
24+
stat, err := os.Stat(path)
25+
if err != nil {
26+
if os.IsNotExist(err) {
27+
return false, nil
28+
}
29+
return false, err
30+
}
31+
if stat.Mode()&os.ModeNamedPipe == os.ModeNamedPipe {
32+
return true, nil
33+
}
34+
return false, nil
35+
}

0 commit comments

Comments
 (0)