...

Source file src/github.com/containerd/fifo/handle_nolinux.go

Documentation: github.com/containerd/fifo

     1  //go:build !linux && !windows
     2  
     3  /*
     4     Copyright The containerd Authors.
     5  
     6     Licensed under the Apache License, Version 2.0 (the "License");
     7     you may not use this file except in compliance with the License.
     8     You may obtain a copy of the License at
     9  
    10         http://www.apache.org/licenses/LICENSE-2.0
    11  
    12     Unless required by applicable law or agreed to in writing, software
    13     distributed under the License is distributed on an "AS IS" BASIS,
    14     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15     See the License for the specific language governing permissions and
    16     limitations under the License.
    17  */
    18  
    19  package fifo
    20  
    21  import (
    22  	"fmt"
    23  	"syscall"
    24  )
    25  
    26  type handle struct {
    27  	fn  string
    28  	dev uint64
    29  	ino uint64
    30  }
    31  
    32  func getHandle(fn string) (*handle, error) {
    33  	var stat syscall.Stat_t
    34  	if err := syscall.Stat(fn, &stat); err != nil {
    35  		return nil, fmt.Errorf("failed to stat %v: %w", fn, err)
    36  	}
    37  
    38  	h := &handle{
    39  		fn:  fn,
    40  		dev: uint64(stat.Dev), //nolint:unconvert,nolintlint
    41  		ino: uint64(stat.Ino), //nolint:unconvert,nolintlint
    42  	}
    43  
    44  	return h, nil
    45  }
    46  
    47  func (h *handle) Path() (string, error) {
    48  	var stat syscall.Stat_t
    49  	if err := syscall.Stat(h.fn, &stat); err != nil {
    50  		return "", fmt.Errorf("path %v could not be statted: %w", h.fn, err)
    51  	}
    52  	if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino { //nolint:unconvert,nolintlint
    53  		return "", fmt.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn)
    54  	}
    55  	return h.fn, nil
    56  }
    57  
    58  func (h *handle) Name() string {
    59  	return h.fn
    60  }
    61  
    62  func (h *handle) Close() error {
    63  	return nil
    64  }
    65  

View as plain text