[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: tempfile <-> IO::Handle::new_tmpfile?

"Marcelo E. Magallon" <mmagallo@efis.ucr.ac.cr> writes:

>    can I use IO::Handle::new_tmpfile in an Perl script that's run on
>  postinst?
> The package has to Predepend on perl, right? I'll use this
>  tempfile to modify a conffile (it *has* to be modified, it's not an
>  option)... what's the proper way of moving the file back into place?
>  I think:
>    system "cat $tempfile > $conffile";

I really dislike Perl scripts that use system() when Perl is quite
capable of doing it.  Wouldn't File::Copy do it?

In any case, IO::File::new_tmpfile() unlinks the temporary file, so
you'd have to do File::Copy::copy($filehandle, $conffile) anyway.

You only have to worry about security problems with temporary files if
you use /tmp anyway, so I'd recommend something like:

    open(NEW, "> /etc/conffile.new")
	or die "pkg.postinst: open conffile.new: $!\n";
    # Write stuff to NEW.
	or die "pkg.postinst: close conffile.new: $!\n";
    rename("/etc/conffile.new", "/etc/conffile")
	or die "pkg.postinst: rename /etc/conffile.new /etc/conffile: $!\n";

Make sure the postrm removes the changes when someone downgrades, if

	 Carey Evans  http://home.clear.net.nz/pages/c.evans/

	    "As a concept, virtual reality seems to appeal
              to people who spend a lot of time indoors."  - Gregory Benford

To UNSUBSCRIBE, email to debian-mentors-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Reply to: