use TOML;
use POSIX;
use Fcntl qw(LOCK_EX);
-use Cwd;
my $self = $0; $self =~ s{^.*/(?=.)}{};
-my $worksphere = fastcwd // die "$self: Cwd::fastcwd failed: $!\n";
+our $worksphere = getcwd() // die "$self: getcwd failed: $!\n";
$worksphere =~ s{/[^/]+}{} or die "$self: cwd \`$worksphere' unsupported!\n";
our $lockfile = "../.nailing-cargo-sphere.lock";
sub toml_or_enoent ($$) {
my ($f,$what) = @_;
my $toml = read_or_enoent($f) // return;
- my ($toml,$e) = from_toml($toml);
- die "$self: parse TOML: $what: $f: $e\n" if defined $e;
- $toml;
+ my ($v,$e) = from_toml($toml);
+ die "$self: parse TOML: $what: $f: $e\n" unless defined $v;
+ die "$e ?" if length $e;
+ $v;
}
sub load1config ($) {
my $cfgleaf = ".nailing-cargo-cfg.toml";
load1config("/etc/nailing-cargo/cfg.toml");
load1config("$worksphere/$cfgleaf");
- load1config("$HOME/$cfgleaf") if defined $HOME;
+ load1config("$ENV{HOME}/$cfgleaf") if defined $ENV{HOME};
}
sub getcfg ($$) {
my ($k, $def) = @_;
foreach my $cfg (@configs) {
- my $v = $cfg{$k};
+ my $v = $cfg->{$k};
return $v if defined $v;
}
- return $df;
+ return $def;
}
-sub lock () {
+sub takelock () {
for (;;) {
open LOCK, ">", $lockfile or die "$0: open/create $lockfile: $!\n";
flock LOCK, LOCK_EX or die "$0: lock $lockfile: $!\n";
next if $! == ENOENT;
die "$0: stat $lockfile: $!\n";
}
- last if "@fstat[0..5]" == "@stat[0..5]";
+ last if "@fstat[0..5]" eq "@stat[0..5]";
}
}
sub unlock () {
if ($toml !~ m{^\s*\[/}m &&
$toml !~ m{^[^\n\#]*\=}m &&
# old non-toml syntax
- $toml =~ s{^[ \t]*([-_0-9a-z]+)[ \t]+(\S+)[ \t]*$}{$1 = $2}mig) {
+ $toml =~ s{^[ \t]*([-_0-9a-z]+)[ \t]+(\S+)[ \t]*$}{$1 = \"$2\"}mig) {
$toml =~ s{^}{[packages\]\n};
$transformed = 1;
}
my $e;
($nail,$e) = from_toml($toml);
- if (defined $e) {
+ if (!defined $nail) {
if ($transformed) {
$toml =~ s/^/ /mg;
print STDERR "$self: $nailfile transformed into TOML:\n$toml\n";
}
die "$0: parse $nailfile: $e\n";
}
- die unless defined $nail;
+ die "$e ?" if length $e;
}
our %manifests;
sub read_manifest ($) {
my ($subdir) = @_;
my $manifest = "../$subdir/Cargo.toml";
- if (defined $manifests{$manifesst}) {
+ if (defined $manifests{$manifest}) {
print STDERR
"$self: warning: $subdir: specified more than once!\n";
return undef;
last if m/^--$/;
}
-lock();
+takelock();
readnail();
readorigs();
+use Data::Dumper;
+print STDERR Dumper(\%packagemap, \%manifests);
+
__DATA__
lock=${PWD%/*}/.nail.lock