bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainenstatic bool wait_for_file(pid_t pid, const char *path)
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen for (unsigned int i = 0; i < 1000; i++) {
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainenstatic void test_file_create_locked_basic(void)
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen const char *path = ".test-file-create-locked";
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen i_unlink_if_exists(".test-temp-file-create-locked-child");
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen fd = file_create_locked(path, &set, &lock, &created, &error);
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen create_file(".test-temp-file-create-locked-child");
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen test_assert(wait_for_file(pid, ".test-temp-file-create-locked-child"));
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen test_assert(file_create_locked(path, &set, &lock, &created, &error) == -1);
9a18972285665fc8ce3709f444f0f1e72e8b71a7Timo Sirainen i_unlink_if_exists(".test-temp-file-create-locked-child");
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainenstatic void test_file_create_locked_mkdir(void)
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen test_begin("file_create_locked() with mkdir");
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen if (unlink_directory(dir, UNLINK_DIRECTORY_FLAG_RMDIR, &error) < 0)
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen i_fatal("unlink_directory(%s) failed: %s", dir, error);
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen /* try without mkdir enabled */
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen test_assert(file_create_locked(path, &set, &lock, &created, &error) == -1);
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen /* try with mkdir enabled */
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen fd = file_create_locked(path, &set, &lock, &created, &error);
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen if (unlink_directory(dir, UNLINK_DIRECTORY_FLAG_RMDIR, &error) < 0)
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen i_fatal("unlink_directory(%s) failed: %s", dir, error);