Mail archive

[Acf] RFC: File editor object

From: Natanael Copa <>
Date: Fri, 13 Oct 2006 18:31:47 +0200


I'm writing a file editor: Ed. I would like to vent some alternatives.
The basic idea is:

-- file is read to table
myfile = Ed:open( filename )

-- table is modifeid (think the file is modified)

-- save table back to file

Now, what I wonder is what is best:

Alternative 1:
Ed:open() will open the file, read data to table and keep the file open
until Ed:close(). This is like opening a file with vim and write and
quit (:wq) when you are done.

Alternative 2:
Ed:open() opens the file, read the data to table and closes the file.
when Ed:save() or Ed:write() is called the file is opened again but in
write mode and the file is overwritten with data in table. this would be
like the in shell:
  data=`sed 's/...../' $filename`
  echo $data > $filename

Only reason I ask is: What happens if some other process deletes the
file while Ed is editing it? Race conditions etc.

What is best do you think?

Natanael Copa
Received on Fri Oct 13 2006 - 18:31:47 UTC