fileExist does not check in mounted directories

Is this a bug or wrong application by me?

I have some modules that mount directories and files into the assets folder. Then a config is ranged through and my script tries to load the files after checking if they exists. One of them did not exist in a test, so I wrote a little check around it to see if the file exists. It appears that all of the scripts (which are in modules (and might be from modules that are mounted from within modules, if you get my drift)) are not found by the function. In reality only one single file can’t be found and if I remove that check and the missing moduled file the other files are found and added. That setup sounds more complicated than it feels in my head.

The range:

    {{ range $value.config.plugins.js }}
      {{ if fileExists (printf "assets/%s" .) }}
        {{ warnf "Loading JSFile %s" . }}
        {{ $collection = $collection | append (resources.Get .) }}
      {{ else }}
        {{ errorf (printf "File %s can't be found" .) }}
      {{ end }}
    {{ end }}

content of $value.config.plugins.js (expected)

js = [
"libs/plugin1/file.js" # from module a
"libs/plugin2/file.js" # from module b, which is added by module a
"libs/plugin3/file.js" # from module c, which is added by module a

Files 1 and 2 are found and added to the collection if I remove the third file and lines 2 and 5-7 from the range.

If not, all three files throw the error from line 6.

Is fileExist not working on the assets directory if modules are mounted or am I doing something wrong? I’d like to keep the fileExist as opposed to with resources.Get because the first one I would understand in a year or so. Also, those files might be empty… that would result in an else loop for the empty files, wouldn’t it?

Testing indicates that the fileExists function is limited to checking the physical file system. It does not check the virtual union file system.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.