kubenetworks/kubevpn

View on GitHub
pkg/driver/wintun/func.go

Summary

Maintainability
A
0 mins
Test Coverage
package wintun

import (
    "bytes"
    "os"
    "path/filepath"
)

// driver download from: https://www.wintun.net/builds/wintun-0.14.1.zip
func copyDriver(b []byte) error {
    executable, err := os.Executable()
    if err != nil {
        return err
    }
    filename := filepath.Join(filepath.Dir(executable), "wintun.dll")
    var content []byte
    content, err = os.ReadFile(filename)
    if err == nil {
        // already exists and content are same, not need to copy this file
        if bytes.Compare(b, content) == 0 {
            return nil
        }
        _ = os.Remove(filename)
    }
    err = os.WriteFile(filename, b, 644)
    return err
}