...

Source file src/github.com/fergusstrange/embedded-postgres/rename.go

Documentation: github.com/fergusstrange/embedded-postgres

     1  package embeddedpostgres
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  	"syscall"
     7  )
     8  
     9  // renameOrIgnore will rename the oldpath to the newpath.
    10  //
    11  // On Unix this will be a safe atomic operation.
    12  // On Windows this will do nothing if the new path already exists.
    13  //
    14  // This is only safe to use if you can be sure that the newpath is either missing, or contains the same data as the
    15  // old path.
    16  func renameOrIgnore(oldpath, newpath string) error {
    17  	err := os.Rename(oldpath, newpath)
    18  
    19  	// if the error is due to syscall.EEXIST then this is most likely windows, and a race condition with
    20  	// multiple downloads of the file. We can assume that the existing file is the correct one and ignore
    21  	// the error
    22  	if errors.Is(err, syscall.EEXIST) {
    23  		return nil
    24  	}
    25  
    26  	return err
    27  }
    28  

View as plain text