It is currently Fri Oct 18, 2019 7:48 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Possible problem with ReadFile
PostPosted: Wed Dec 13, 2017 5:53 am 
Offline
User
User

Joined: Wed May 07, 2008 4:57 am
Posts: 60
Location: Adelaide, South Australia
I am a bit unsure but I suspect there may be an odd problem with ReadFile since 5.60.

I adopted 5.60 when it was released earlier this year and I also updated to 5.61. Since then some of my users began to report odd problems with text files not being read. It took months to track it down to files sometimes not being opened. I only became more certain of this within the last few weeks after adding considerable error trapping. I was able to narrow it down to ReadFile and not ReadString or other commands. Prior to 5.60, this has not been a problem. If the file was present, it was opened reliably.

The critical code snippet is:
Code:
Procedure.l AOPENI(filename$)
  If IsFile(0)              ;If file is already open, close it
    FlushFileBuffers(0)
    CloseFile(0)
  EndIf
  R=ReadFile(0,filename$,#PB_File_SharedRead|#PB_File_NoBuffering|#PB_Ascii)
  T=5
  While R=0      ;If unsuccessful opening, retry 5 times
    Delay(400)
    T-1
    If T<1
      Break
    EndIf
    R=ReadFile(0,filename$,#PB_File_SharedRead|#PB_File_NoBuffering|#PB_Ascii)
  Wend
  ProcedureReturn R
EndProcedure

Procedure$ AREADFILEX()       ;procedure that reads the entire file into one string
  RESULT$=""
  If IsFile(0)
    While Eof(0)=#False
      A$=ReadString(0,#PB_Ascii)
      RESULT$+A$+#CRLF$
    Wend
  EndIf
  ProcedureReturn RESULT$
EndProcedure

Procedure ACLOSE()         ;procedure to close the file
  If IsFile(0)
    FlushFileBuffers(0)
    CloseFile(0)
  EndIf
EndProcedure


The calling code is
Code:
If AOPENI(settingsfile$)=0
  MessageRequester("Notice","Error: unable to open settings file. Contact the help desk.")
  ProcedureReturn
EndIf
SETTINGS$=AREADFILEX()
ACLOSE()
If Len(SETTINGS$)=0
  ;report an error as this should never happen
  ;set up defaults
Else
  ;process parts of the file
EndIf


The problem is not dependent on multi-user access; it can happen with only one user is accessing the file.
This source code has not been changed in nearly two years. At that time the error-trapping loop and the #PB_File_NoBuffering and #PB_Ascii flags were added. The problem, however, has only happened this year.

I am not sure it is a PureBasic bug or not as it has been difficult to track down but it definitely happens with different text files, not always the same one.

I have recompiled my programs using PureBasic 5.45 and so far users not have reported the same problem.

Were any changes made to this command when 5.60 was introduced?

__________________________________________________
Code tags added
16.01.2018
RSBasic


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye