github.com/blend/go-sdk@v1.20220411.3/sourceutil/remove_file.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package sourceutil
     9  
    10  import (
    11  	"context"
    12  	"fmt"
    13  	"os"
    14  )
    15  
    16  // RemoveFile removes a file and prints a debug message if the context sets that flag.
    17  func RemoveFile(ctx context.Context, path string) error {
    18  	if info, err := os.Stat(path); err != nil {
    19  		return err
    20  	} else if info.IsDir() {
    21  		return fmt.Errorf("cannot remove file; %s is a directory", path)
    22  	}
    23  	return os.Remove(path)
    24  }