Why does directoryExists test true but cfdirectory fails?

我只是一个虾纸丫 提交于 2020-01-03 13:08:24

问题


I have a page that accesses in-memory files. We have 10 - 20k files stored in hundreds of directories (up to 2000). All directories and files are created programmatically. There are no permissions set or changed. All files use the default CF account, which we have had no issues with.

Every once in a while, we get an error. We test for the existence of a directory. If it exists, we get the contents of the directory and do something with the files. We are successfully able to read directories whether there is content or not.

<cfscript>
    LOCAL.RamFileDir = "ram://CatSearchMenu/9160";
</cfscript>

<cfoutput>
<cfif directoryExists("#LOCAL.RamFileDir#") eq true>
    #LOCAL.RamFileDir# exists<br>
    <cfdirectory name="getRamFiles" directory="#LOCAL.RamFileDir#" action="list">
    <cfdump var="#getRamFiles#">
<cfelse>
    #LOCAL.RamFileDir# DOES NOT exist<br>
</cfif>     
</cfoutput>

Here's the error I am getting...

An error occurred when performing a file operation listFiles on file /CatSearchMenuSubCats/9160.

The cause of this exception was: org.apache.commons.vfs2.FileSystemException: Could not list the contents of folder "ram:///CatSearchMenuSubCats/9160"..

The error occurred in E:/INETPUB/WWWROOT/AVCATALOGS/...: line 92

 91 :                   <!--- GET THE FILES --->
 92 :                   <cfdirectory name="getRamFiles" 
 93 :                       directory="#LOCAL.RamFileDir#" 
 94 :                       action="list">

The getFileInfo() function shows that there's nothing preventing me from accessing the directory.

The image below shows a slightly different path. The path is different for the sake of brevity.

EXTRA BOUNTY INFO ~ added 6/9/2014

This specific directory passes the directoryExists() test but when we use cfdirectory to list the contents, it chokes. How could it pass one test and then fail?

We cannot do any cfdirectory action on this directory, no create, delete, or list action will work. We can, however, access the files within the directory if we know the name of the file.

When we restart the ColdFusion services, the ram is wiped out. Automatically, the files are created as needed by another process. The files can be up and running and working fine for days on end. Then, suddenly, just ONE of the directories is not available. It's never the same directory. A few days later, ONE MORE directory becomes unavailable. Again, every other directory (of the two thousand) works perfectly. Again, all of the files within any directory is perfectly accessible. Once a directory becomes unavailable, it remains that way until we restart the ColdFusion services.

<cfscript>
// SET RAM FILE BASE
LOCAL.RamFileBase = "ram://includes";
</cfscript>

<!--- TEST THE BASE --->
<cfoutput>
<cfif directoryExists("#LOCAL.RamFileBase#") eq true>
<h1>#LOCAL.RamFileBase# BASE EXISTS</h1>

<!--- GET THE BASE --->
<cfdirectory name="getRamBase" directory="#LOCAL.RamFileBase#" action="list">

<!--- LOOP THROUGH THE BASE --->        
<cfloop query="getRamBase">

    <!--- TEST THE SUB DIRECTORY --->
    <cfif directoryExists("#LOCAL.RamFileBase#/#getRamBase.Name#") eq true>
        <h3>#LOCAL.RamFileBase#/#getRamBase.Name# SUB DIR EXISTS</h3>

        <!--- GET THE SUB DIRECTORY --->
        <cfdirectory name="getRamSubDir" directory="#LOCAL.RamFileBase#/#getRamBase.Name#" action="list">

        <!--- LOOP THROUGH THE SUB DIRECTORY --->
        <cfloop query="getRamSubDir">

            <!--- TEST THE SUB SUB DIRECTORY ~ WHERE THE FILES ARE --->
            <cfif directoryExists("#LOCAL.RamFileBase#/#getRamBase.Name#/#getRamSubDir.Name#") eq true>
                <b>#LOCAL.RamFileBase#/#getRamBase.Name#/#getRamSubDir.Name#</b> SUB SUB DIR EXISTS<br>

                <!--- GET THE FILES IN THE SUB SUB DIRECTORY --->
                                    <!--- THIS IS WHERE THE PROBLEM IS --->
                <cfdirectory name="getRamFiles" 
                        directory="#LOCAL.RamFileBase#/#getRamBase.Name#/#getRamSubDir.Name#" 
                        action="list" 
                        sort="DateLastModified ASC">

                    <!--- LOOP THROUGH THE FILES --->
                    <cfloop query="getRamFiles">


回答1:


A couple of observations and bad Adobe documentation:

Using the LOCAL scope is probably OK but I'd prefer you not since the code is not within a function.

While browsing the Adobe docs, I noticed frequent use of 3 forward slashes when referring to in-memory files. ex: ram:/// Not using 3 may be a subtle issue.

According to http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSe9cbe5cf462523a0-70e2363b121825b20e7-8000.html , the <cfdirectory /> tag does not appear in the "the following tags are supported for in-memory files:" section. This is troubling since an example just above that section on the same page IS using <cfdirectory />

Finally, I don't believe in-memory functionality was meant to deal with 10-20k files stored in hundreds of directories. :) A traditional file system, outside the web root, using proper locking, may be a better option.



来源:https://stackoverflow.com/questions/23892638/why-does-directoryexists-test-true-but-cfdirectory-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!