Author: eelco
Date: Sun May 8 21:22:21 2011
New Revision: 27189
URL: https://svn.nixos.org/websvn/nix/?rev=27189&sc=1
Log:
* Update state.json.
Modified:
cloud/trunk/src/nixos-deploy-network.pl
Modified: cloud/trunk/src/nixos-deploy-network.pl
==============================================================================
--- cloud/trunk/src/nixos-deploy-network.pl Sun May 8 21:16:10 2011
(r27188)
+++ cloud/trunk/src/nixos-deploy-network.pl Sun May 8 21:22:21 2011
(r27189)
@@ -15,6 +15,7 @@
my @machines = ();
my $outPath;
my $state;
+my $stateFile = "./state.json";
my $myDir = dirname(Cwd::abs_path($0));
@@ -87,14 +88,20 @@
sub readState {
local $/;
- open(my $fh, '<', './state.json') or die "$!";
- $state = decode_json <$fh>;
+ if (-e $stateFile) {
+ open(my $fh, '<', $stateFile) or die "$!";
+ $state = decode_json <$fh>;
+ } else {
+ $state = { machines => {} };
+ }
}
sub writeState {
- open(my $fh, '>', './state.json.new') or die "$!";
+ open(my $fh, '>', "$stateFile.new") or die "$!";
print $fh encode_json($state);
+ close $fh;
+ rename "$stateFile.new", $stateFile or die;
}
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits