github.com/anishathalye/periscope@v0.3.5/internal/periscope/forget.go (about)

     1  package periscope
     2  
     3  import (
     4  	"github.com/anishathalye/periscope/internal/herror"
     5  
     6  	"fmt"
     7  	"os"
     8  	"path/filepath"
     9  )
    10  
    11  type ForgetOptions struct {
    12  }
    13  
    14  func (ps *Periscope) Forget(paths []string, options *ForgetOptions) herror.Interface {
    15  	// we don't need paths to exist before doing work, but we do need to be able to determine absolute paths
    16  	var herr herror.Interface
    17  	tx, err := ps.db.Begin()
    18  	if err != nil {
    19  		return err
    20  	}
    21  	for _, path := range paths {
    22  		abs, err := filepath.Abs(path)
    23  		if err != nil {
    24  			fmt.Fprintf(ps.errStream, "cannot forget '%s': cannot determine absolute path\n", path)
    25  			herr = herror.Silent()
    26  		} else {
    27  			err := tx.RemoveDir(abs, 0, 0)
    28  			if err != nil {
    29  				return err
    30  			}
    31  			// format path for nicer printing
    32  			if path[len(path)-1] != os.PathSeparator {
    33  				path = path + string(os.PathSeparator)
    34  			}
    35  			fmt.Fprintf(ps.outStream, "forgot %s*\n", path)
    36  		}
    37  	}
    38  	if err := tx.Commit(); err != nil {
    39  		return err
    40  	}
    41  	return herr
    42  }