Selaa lähdekoodia

add file soft link path resolve support (#1482)

* add file soft link path resolve

* add configuration file soft link path resolve support
Nanyu 2 vuotta sitten
vanhempi
sitoutus
eaf401eda9
2 muutettua tiedostoa jossa 12 lisäystä ja 3 poistoa
  1. 6 2
      common/platform/filesystem/file.go
  2. 6 1
      infra/conf/serial/builder.go

+ 6 - 2
common/platform/filesystem/file.go

@@ -3,7 +3,7 @@ package filesystem
 import (
 	"io"
 	"os"
-
+	"path/filepath"
 	"github.com/xtls/xray-core/common/buf"
 	"github.com/xtls/xray-core/common/platform"
 )
@@ -11,7 +11,11 @@ import (
 type FileReaderFunc func(path string) (io.ReadCloser, error)
 
 var NewFileReader FileReaderFunc = func(path string) (io.ReadCloser, error) {
-	return os.Open(path)
+	resolved_path,err:=filepath.EvalSymlinks(path)
+	if err!= nil{
+		return nil,err
+	}
+	return os.Open(resolved_path)
 }
 
 func ReadFile(path string) ([]byte, error) {

+ 6 - 1
infra/conf/serial/builder.go

@@ -2,6 +2,7 @@ package serial
 
 import (
 	"io"
+	"path/filepath"
 
 	"github.com/xtls/xray-core/core"
 	"github.com/xtls/xray-core/infra/conf"
@@ -10,7 +11,11 @@ import (
 
 func BuildConfig(files []string, formats []string) (*core.Config, error) {
 	cf := &conf.Config{}
-	for i, file := range files {
+	for i, file_ := range files {
+		file, err := filepath.EvalSymlinks(file_)
+		if err != nil {
+			return nil, err
+		}
 		newError("Reading config: ", file).AtInfo().WriteToLog()
 		r, err := confloader.LoadConfig(file)
 		if err != nil {