@@ -174,10 +174,9 @@ func (a *AdapterFile) GetPaths() []string {
174174 return a .searchPaths .Slice ()
175175}
176176
177- // doGetFilePath returns the absolute configuration file path for the given filename by `file`.
178- // If `file` is not passed, it returns the configuration file path of the default name.
179- // It returns an empty `path` string and an error if the given `file` does not exist.
180- func (a * AdapterFile ) doGetFilePath (fileName string ) (filePath string ) {
177+ // doGetFilePath returns the absolute configuration file path for the given filename by `fileNameOrPath`.
178+ // The `fileNameOrPath` can be either a file name or the file path.
179+ func (a * AdapterFile ) doGetFilePath (fileNameOrPath string ) (filePath string ) {
181180 var (
182181 tempPath string
183182 resFile * gres.File
@@ -186,7 +185,7 @@ func (a *AdapterFile) doGetFilePath(fileName string) (filePath string) {
186185 // Searching resource manager.
187186 if ! gres .IsEmpty () {
188187 for _ , tryFolder := range resourceTryFolders {
189- tempPath = tryFolder + fileName
188+ tempPath = tryFolder + fileNameOrPath
190189 if resFile = gres .Get (tempPath ); resFile != nil {
191190 fileInfo , _ = resFile .Stat ()
192191 if fileInfo != nil && ! fileInfo .IsDir () {
@@ -198,7 +197,7 @@ func (a *AdapterFile) doGetFilePath(fileName string) (filePath string) {
198197 a .searchPaths .RLockFunc (func (array []string ) {
199198 for _ , searchPath := range array {
200199 for _ , tryFolder := range resourceTryFolders {
201- tempPath = searchPath + tryFolder + fileName
200+ tempPath = searchPath + tryFolder + fileNameOrPath
202201 if resFile = gres .Get (tempPath ); resFile != nil {
203202 fileInfo , _ = resFile .Stat ()
204203 if fileInfo != nil && ! fileInfo .IsDir () {
@@ -215,16 +214,12 @@ func (a *AdapterFile) doGetFilePath(fileName string) (filePath string) {
215214
216215 // Searching local file system.
217216 if filePath == "" {
218- // Absolute path.
219- /*if filePath = gfile.RealPath(fileName); filePath != "" && !gfile.IsDir(filePath) {
220- return
221- }*/
222217 a .searchPaths .RLockFunc (func (array []string ) {
223218 for _ , searchPath := range array {
224219 searchPath = gstr .TrimRight (searchPath , `\/` )
225220 for _ , tryFolder := range localSystemTryFolders {
226221 relativePath := gstr .TrimRight (
227- gfile .Join (tryFolder , fileName ),
222+ gfile .Join (tryFolder , fileNameOrPath ),
228223 `\/` ,
229224 )
230225 if filePath , _ = gspath .Search (searchPath , relativePath ); filePath != "" &&
@@ -235,9 +230,9 @@ func (a *AdapterFile) doGetFilePath(fileName string) (filePath string) {
235230 }
236231 })
237232 }
233+ // The `fileNameOrPath` can be a file path.
238234 if filePath == "" {
239- // Absolute path.
240- if filePath = gfile .RealPath (fileName ); filePath != "" && ! gfile .IsDir (filePath ) {
235+ if filePath = gfile .RealPath (fileNameOrPath ); filePath != "" && ! gfile .IsDir (filePath ) {
241236 return
242237 }
243238 }
@@ -247,23 +242,24 @@ func (a *AdapterFile) doGetFilePath(fileName string) (filePath string) {
247242// GetFilePath returns the absolute configuration file path for the given filename by `file`.
248243// If `file` is not passed, it returns the configuration file path of the default name.
249244// It returns an empty `path` string and an error if the given `file` does not exist.
250- func (a * AdapterFile ) GetFilePath (fileName ... string ) (filePath string , err error ) {
245+ func (a * AdapterFile ) GetFilePath (fileNameOrPath ... string ) (filePath string , err error ) {
251246 var (
252- fileExtName string
253- tempFileName string
254- usedFileName = a .defaultName
247+ fileExtName string
248+ tempFileNameOrPath string
249+ usedFileNameOrPath = a .defaultFileNameOrPath
255250 )
256- if len (fileName ) > 0 {
257- usedFileName = fileName [0 ]
251+ if len (fileNameOrPath ) > 0 {
252+ usedFileNameOrPath = fileNameOrPath [0 ]
258253 }
259- fileExtName = gfile .ExtName (usedFileName )
260- if filePath = a .doGetFilePath (usedFileName ); (filePath == "" || gfile .IsDir (filePath )) && ! gstr .InArray (supportedFileTypes , fileExtName ) {
254+ fileExtName = gfile .ExtName (usedFileNameOrPath )
255+ if filePath = a .doGetFilePath (usedFileNameOrPath ); (filePath == "" || gfile .IsDir (filePath )) &&
256+ ! gstr .InArray (supportedFileTypes , fileExtName ) {
261257 // If it's not using default configuration or its configuration file is not available,
262258 // it searches the possible configuration file according to the name and all supported
263259 // file types.
264260 for _ , fileType := range supportedFileTypes {
265- tempFileName = fmt .Sprintf (`%s.%s` , usedFileName , fileType )
266- if filePath = a .doGetFilePath (tempFileName ); filePath != "" {
261+ tempFileNameOrPath = fmt .Sprintf (`%s.%s` , usedFileNameOrPath , fileType )
262+ if filePath = a .doGetFilePath (tempFileNameOrPath ); filePath != "" {
267263 break
268264 }
269265 }
@@ -275,12 +271,12 @@ func (a *AdapterFile) GetFilePath(fileName ...string) (filePath string, err erro
275271 if ! gstr .InArray (supportedFileTypes , fileExtName ) {
276272 buffer .WriteString (fmt .Sprintf (
277273 `possible config files "%s" or "%s" not found in resource manager or following system searching paths:` ,
278- usedFileName , fmt .Sprintf (`%s.%s` , usedFileName , gstr .Join (supportedFileTypes , "/" )),
274+ usedFileNameOrPath , fmt .Sprintf (`%s.%s` , usedFileNameOrPath , gstr .Join (supportedFileTypes , "/" )),
279275 ))
280276 } else {
281277 buffer .WriteString (fmt .Sprintf (
282278 `specified config file "%s" not found in resource manager or following system searching paths:` ,
283- usedFileName ,
279+ usedFileNameOrPath ,
284280 ))
285281 }
286282 a .searchPaths .RLockFunc (func (array []string ) {
@@ -297,7 +293,10 @@ func (a *AdapterFile) GetFilePath(fileName ...string) (filePath string, err erro
297293 }
298294 })
299295 } else {
300- buffer .WriteString (fmt .Sprintf (`cannot find config file "%s" with no filePath configured` , usedFileName ))
296+ buffer .WriteString (fmt .Sprintf (
297+ `cannot find config file "%s" with no filePath configured` ,
298+ usedFileNameOrPath ,
299+ ))
301300 }
302301 err = gerror .NewCode (gcode .CodeNotFound , buffer .String ())
303302 }
0 commit comments