Mail archive
acf

Re: [Acf] RFC: File editor object

From: Nathan Angelacos <nangel_at_nothome.org>
Date: Sat, 14 Oct 2006 09:40:36 -0400

Natanael Copa wrote:
> Hi,
>
> 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)
> myfile:do_some_modifications_to_some_lines()
>
> -- save table back to file
> myfile:save_and_close()
>
>
>
> 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?

Both have their pros and cons. Since ACF is being built for alpine, a
"Router", hopefully there is only one admin editing files at any given
time. I would vote for option 2, since its simpler.
Received on Sat Oct 14 2006 - 09:40:36 GMT