github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/paths/logfile_windows.go (about)

     1  // Copyright 2019 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package paths
     5  
     6  import (
     7  	"os"
     8  
     9  	"github.com/juju/errors"
    10  )
    11  
    12  // LogfilePermission is the file mode to use for log files.
    13  // Windows only uses the first byte, 0400 for read-only, 0600 for read/write.
    14  const LogfilePermission = os.FileMode(0600)
    15  
    16  // Windows doesn't have the same issues around ownership. In fact calling
    17  // Chown on windows always fails.
    18  
    19  // SetSyslogOwner is a no-op on windows.
    20  func SetSyslogOwner(filename string) error {
    21  	return nil
    22  }
    23  
    24  // SetOwnership is a no-op on windows.
    25  func SetOwnership(filePath string, wantedUser string, wantedGroup string) error {
    26  	return nil
    27  }
    28  
    29  // PrimeLogFile ensures that the given log file is created with the
    30  // correct mode and ownership.
    31  func PrimeLogFile(path string) error {
    32  	f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, LogfilePermission)
    33  	if err != nil {
    34  		return errors.Trace(err)
    35  	}
    36  	return errors.Trace(f.Close())
    37  }
    38  
    39  // SyslogUserGroup returns the names of the user and group that own the log files.
    40  func SyslogUserGroup() (string, string) {
    41  	return "noone", "noone"
    42  }