...

Source file src/github.com/containerd/continuity/fs/du_windows.go

Documentation: github.com/containerd/continuity/fs

     1  //go:build windows
     2  // +build windows
     3  
     4  /*
     5     Copyright The containerd Authors.
     6  
     7     Licensed under the Apache License, Version 2.0 (the "License");
     8     you may not use this file except in compliance with the License.
     9     You may obtain a copy of the License at
    10  
    11         http://www.apache.org/licenses/LICENSE-2.0
    12  
    13     Unless required by applicable law or agreed to in writing, software
    14     distributed under the License is distributed on an "AS IS" BASIS,
    15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16     See the License for the specific language governing permissions and
    17     limitations under the License.
    18  */
    19  
    20  package fs
    21  
    22  import (
    23  	"context"
    24  	"os"
    25  	"path/filepath"
    26  )
    27  
    28  func diskUsage(ctx context.Context, roots ...string) (Usage, error) {
    29  	var size int64
    30  
    31  	// TODO(stevvooe): Support inodes (or equivalent) for windows.
    32  
    33  	for _, root := range roots {
    34  		if err := filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
    35  			if err != nil {
    36  				return err
    37  			}
    38  
    39  			select {
    40  			case <-ctx.Done():
    41  				return ctx.Err()
    42  			default:
    43  			}
    44  
    45  			size += fi.Size()
    46  			return nil
    47  		}); err != nil {
    48  			return Usage{}, err
    49  		}
    50  	}
    51  
    52  	return Usage{
    53  		Size: size,
    54  	}, nil
    55  }
    56  
    57  func diffUsage(ctx context.Context, a, b string) (Usage, error) {
    58  	var size int64
    59  
    60  	if err := Changes(ctx, a, b, func(kind ChangeKind, _ string, fi os.FileInfo, err error) error {
    61  		if err != nil {
    62  			return err
    63  		}
    64  
    65  		if kind == ChangeKindAdd || kind == ChangeKindModify {
    66  			size += fi.Size()
    67  
    68  			return nil
    69  
    70  		}
    71  		return nil
    72  	}); err != nil {
    73  		return Usage{}, err
    74  	}
    75  
    76  	return Usage{
    77  		Size: size,
    78  	}, nil
    79  }
    80  

View as plain text