Looking at your program, it seems die is probably a nice way to make this whole thing atomic. I'm assuming it doesn't matter if the staging directory is in a state of disarray, as long as the rsync command is not run. Other than the issue with die's return value not being what you seem to expect, your code looks ok.

That said, there are some minor stylistic problems I see with your code. Here's how I would have written the lines you pasted, if I were using Perl at all (this thing reeks of a shell script, though if it's a learning experience, then hopefully I'm helping you learn a bit):

chdir $staging_dir or die "chdir: $!"; system qw(svn update base) and die "up base: $!"; system qw(svn update hostgroup) and die "up hostgroup: $!"; system qw(svn update host) and die "up host: $!"; system $copier_prog, $staging_dir, $pre_launch_dir, $copier_conf and die "copy: $!"; system $perm_prog, -c => $perm_conf and die "permissions: $!"; system qw(rsync -avz --exclude=.svn --delete-after), $pre_launch_dir, $live_dir and die "rsync: $!";

There are a few things I've done here. First, I removed superfluous quotes. In Perl, unlike most shells, you don't need quotes around your variables to be safe. In fact, doing string interpolation when you don't really want to can have negative consequences. I also made use of the qw and => operators to remove a few more quotes, and I removed some unneeded parentheses. I find these things just clutter up the program. I also shortened the error messages and variables, though that was mainly to make the code fit better in a browser.

Update: fixed silly bug caused by last-minute variable renaming.


In reply to Re: Is "die" the best way to be atomic? by revdiablo
in thread Is "die" the best way to be atomic? by BuddhaNature

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.