3 Replies Latest reply on Nov 8, 2007 8:30 PM by cf_dev2

    CFFILE Holding File Locks

      I have a CF page that reads some tab-delimited text files for processing. After it reads a file it then calls a CF page to move the file to a new location. It moves the file, but it does not delete the old version -- and a filesystem delete on the file fails -- it appears as if the CF server has the file locked. If I shut down the server and restart it, it clears the lock.

      <cfif #url.vendor# is "LOWES">
      <cflock timeout="10" scope="server" throwOnTimeout="no" type="exclusive">
      <cffile action="move"
        • 1. Re: CFFILE Holding File Locks
          Kuromaku Level 1
          Looks like rename locks itself -- the attached block solves the problem
          • 2. Re: CFFILE Holding File Locks
            William_At_FAA Level 1
            Generally when manipulating files you used a named <cflock> instead of a scope like so:

            <cflock name="#Variables.myFileName#" timeout="5" type="exclusive">

            In your code in the second example I'm not sure about the function of the loop at all... I guess you are trying to delay to make sure the copy operation completes before deleting. But looping from 1 to 10 is arbitrary and depending on other concurrent processes, server speed, RAM, etc. and so basically it is unreliable.
            • 3. Re: CFFILE Holding File Locks
              cf_dev2 Level 1
              Perhaps they mean changing from a "move" to a "copy" + "delete" resolved the problem.

              > used a named <cflock> instead
              Yes, consider using a more granular lock, instead of placing an exclusive lock on the server scope. Though it looks like locking was removed entirely from the final code.