Skip to content

Commit

Permalink
Create lock files if they don't exist when trying to open the lock.
Browse files Browse the repository at this point in the history
This lets us be a bit more flexible when upgrading old databases.
  • Loading branch information
gittup committed Jul 19, 2017
1 parent bfcdab2 commit 4e418d7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/tup/flock/fcntl.c
Expand Up @@ -30,7 +30,7 @@ int tup_lock_open(const char *lockname, tup_lock_t *lock)
{
int fd;

fd = openat(tup_top_fd(), lockname, O_RDWR);
fd = openat(tup_top_fd(), lockname, O_RDWR | O_CREAT, 0666);
if(fd < 0) {
perror(lockname);
fprintf(stderr, "tup error: Unable to open lockfile.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/tup/flock/lock_file.c
Expand Up @@ -34,7 +34,7 @@ int tup_lock_open(const char *lockname, tup_lock_t *lock)
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
OPEN_ALWAYS,
0,
NULL);
if(h == INVALID_HANDLE_VALUE) {
Expand Down
12 changes: 0 additions & 12 deletions src/tup/init.c
Expand Up @@ -225,18 +225,6 @@ int init_command(int argc, char **argv)
return -1;
}

if(creat(TUP_OBJECT_LOCK, 0666) < 0) {
perror(TUP_OBJECT_LOCK);
return -1;
}
if(creat(TUP_SHARED_LOCK, 0666) < 0) {
perror(TUP_SHARED_LOCK);
return -1;
}
if(creat(TUP_TRI_LOCK, 0666) < 0) {
perror(TUP_TRI_LOCK);
return -1;
}
if(!db_sync) {
FILE *f = fopen(TUP_OPTIONS_FILE, "w");
if(!f) {
Expand Down
10 changes: 4 additions & 6 deletions test/t0000-init.sh
Expand Up @@ -18,11 +18,9 @@

. ./tup.sh

for i in db object shared tri; do
if [ ! -f ".tup/$i" ]; then
echo ".tup/$i not created!" 1>&2
exit 1
fi
done
if [ ! -f ".tup/db" ]; then
echo ".tup/db not created!" 1>&2
exit 1
fi

eotup
12 changes: 5 additions & 7 deletions test/t0001-init-tmp.sh
Expand Up @@ -33,13 +33,11 @@ cleanup
mkdir $tmpdir
cd $tmpdir
tup init
for i in db object shared tri; do
if [ ! -f ".tup/$i" ]; then
echo ".tup/$i not created!" 1>&2
cleanup
exit 1
fi
done
if [ ! -f ".tup/db" ]; then
echo ".tup/db not created!" 1>&2
cleanup
exit 1
fi
cleanup

cd $tupcurdir
Expand Down
10 changes: 4 additions & 6 deletions test/t0002-init-dir.sh
Expand Up @@ -19,11 +19,9 @@
. ./tup.sh

tup init --force foo
for i in db object shared tri; do
if [ ! -f "foo/.tup/$i" ]; then
echo "foo/.tup/$i not created!" 1>&2
exit 1
fi
done
if [ ! -f "foo/.tup/db" ]; then
echo "foo/.tup/db not created!" 1>&2
exit 1
fi

eotup
10 changes: 4 additions & 6 deletions test/t0003-init-subdir.sh
Expand Up @@ -19,11 +19,9 @@
. ./tup.sh

tup init --force foo/bar/baz
for i in db object shared tri; do
if [ ! -f "foo/bar/baz/.tup/$i" ]; then
echo "foo/bar/baz/.tup/$i not created!" 1>&2
exit 1
fi
done
if [ ! -f "foo/bar/baz/.tup/db" ]; then
echo "foo/bar/baz/.tup/db not created!" 1>&2
exit 1
fi

eotup

0 comments on commit 4e418d7

Please sign in to comment.