Browse Source

fix saving a backup removing files from main project

audio_pool_remove_unused() would remove unused files from the main
project instead of the backup project, when saving a backup
audio_region_bpm_change_fix
parent
commit
2d5f3f343d
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 4
      src/audio/clip.c
  2. 20
      src/audio/pool.c
  3. 3
      tests/actions/mixer_selections_action.c
  4. 242
      tests/audio/pool.c
  5. 20
      tests/helpers/project.h
  6. 5
      tests/project.c

4
src/audio/clip.c

@ -702,8 +702,8 @@ audio_clip_remove_and_free ( @@ -702,8 +702,8 @@ audio_clip_remove_and_free (
AudioClip * self,
bool backup)
{
char * path = audio_clip_get_path_in_pool (
self, F_NOT_BACKUP);
char * path =
audio_clip_get_path_in_pool (self, backup);
g_message ("removing clip at %s", path);
g_return_if_fail (path);
io_remove (path);

20
src/audio/pool.c

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2019-2021 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
#include <stdlib.h>

3
tests/actions/mixer_selections_action.c

@ -1277,8 +1277,7 @@ test_undoing_deletion_of_multiple_inserts (void) @@ -1277,8 +1277,7 @@ test_undoing_deletion_of_multiple_inserts (void)
test_helper_zrythm_cleanup ();
}
#if defined(HAVE_HELM) \
|| defined(HAVE_CARLA_RACK) \
#if defined(HAVE_HELM) || defined(HAVE_CARLA_RACK) \
|| (defined(HAVE_CARLA) && defined(HAVE_NOIZEMAKER))
static void
_test_replace_instrument (

242
tests/audio/pool.c

@ -20,103 +20,159 @@ @@ -20,103 +20,159 @@
static void
test_remove_unused (void)
{
test_helper_zrythm_init ();
/* create many audio tracks with region to push
* the first few off the undo stack */
char * filepath = g_build_filename (
TESTS_SRCDIR, "test_start_with_signal.mp3",
NULL);
SupportedFile * file =
supported_file_new_from_path (filepath);
int num_tracks_before = TRACKLIST->num_tracks;
track_create_with_action (
TRACK_TYPE_AUDIO, NULL, file, PLAYHEAD,
num_tracks_before, 1, NULL);
/* delete the first track so that the clip for it
* will no longer exist (pushed off undo stack) */
track_select (
TRACKLIST->tracks[num_tracks_before], F_SELECT,
F_NOT_EXCLUSIVE, F_NO_PUBLISH_EVENTS);
tracklist_selections_action_perform_delete (
TRACKLIST_SELECTIONS, PORT_CONNECTIONS_MGR,
NULL);
/* create more tracks */
for (int i = 0; i < (ZRYTHM->undo_stack_len + 4);
i++)
/* on first iteration, run the whole logic
* on second iteration, just check that no files
* in the main project are removed when saving
* a backup */
for (int i = 0; i < 2; i++)
{
test_helper_zrythm_init ();
/* create many audio tracks with region to push
* the first few off the undo stack */
char * filepath = g_build_filename (
TESTS_SRCDIR, "test_start_with_signal.mp3",
NULL);
SupportedFile * file =
supported_file_new_from_path (filepath);
int num_tracks_before = TRACKLIST->num_tracks;
track_create_with_action (
TRACK_TYPE_AUDIO, NULL, file, PLAYHEAD,
TRACKLIST->num_tracks, 1, NULL);
num_tracks_before, 1, NULL);
/* save and reload the project */
test_project_save_and_reload ();
/* delete the first track so that the clip for it
* will no longer exist (pushed off undo stack) */
track_select (
TRACKLIST->tracks[num_tracks_before],
F_SELECT, F_NOT_EXCLUSIVE,
F_NO_PUBLISH_EVENTS);
tracklist_selections_action_perform_delete (
TRACKLIST_SELECTIONS, PORT_CONNECTIONS_MGR,
NULL);
/* if second iteration, clear undo stacks
* (happens e.g. when removing an
* uninstantiated plugin), then attempt to
* save a backup and then attempt to load the
* main project again */
if (i == 1)
{
char * dir = g_strdup (PROJECT->dir);
int ret = project_save (
PROJECT, PROJECT->dir, F_NOT_BACKUP, 0,
F_NO_ASYNC);
g_assert_cmpint (ret, ==, 0);
undo_manager_clear_stacks (
UNDO_MANAGER, F_FREE);
ret = project_save (
PROJECT, PROJECT->dir, F_BACKUP, 0,
F_NO_ASYNC);
g_assert_cmpint (ret, ==, 0);
g_assert_nonnull (PROJECT->backup_dir);
/* free the project */
object_free_w_func_and_null (
project_free, PROJECT);
/* load the original project */
char * prj_filepath = g_build_filename (
dir, PROJECT_FILE, NULL);
g_free (dir);
ret = project_load (prj_filepath, false);
g_free (prj_filepath);
g_assert_cmpint (ret, ==, 0);
test_helper_zrythm_cleanup ();
break;
}
/* create more tracks */
for (int j = 0;
j < (ZRYTHM->undo_stack_len + 4); j++)
{
track_create_with_action (
TRACK_TYPE_AUDIO, NULL, file, PLAYHEAD,
TRACKLIST->num_tracks, 1, NULL);
}
/* assert all clips still exist */
g_assert_cmpint (
AUDIO_POOL->num_clips, ==,
ZRYTHM->undo_stack_len + 5);
AudioClip * clip = AUDIO_POOL->clips[0];
char * clip_path =
audio_clip_get_path_in_pool (
clip, F_NOT_BACKUP);
g_assert_true (g_file_test (
clip_path, G_FILE_TEST_EXISTS));
AudioClip * clip2 = AUDIO_POOL->clips[1];
char * clip_path2 =
audio_clip_get_path_in_pool (
clip2, F_NOT_BACKUP);
g_assert_true (g_file_test (
clip_path2, G_FILE_TEST_EXISTS));
AudioClip * last_clip =
AUDIO_POOL
->clips[ZRYTHM->undo_stack_len + 4];
char * last_clip_path =
audio_clip_get_path_in_pool (
last_clip, F_NOT_BACKUP);
g_assert_true (g_file_test (
last_clip_path, G_FILE_TEST_EXISTS));
char * undo_manager_yaml = yaml_serialize (
UNDO_MANAGER, &undo_manager_schema);
g_message ("\n%s", undo_manager_yaml);
/* undo and check that last file still exists */
undo_manager_undo (UNDO_MANAGER, NULL);
g_assert_true (g_file_test (
last_clip_path, G_FILE_TEST_EXISTS));
g_assert_cmpint (
AUDIO_POOL->num_clips, ==,
ZRYTHM->undo_stack_len + 5);
g_assert_nonnull (
AUDIO_POOL
->clips[ZRYTHM->undo_stack_len + 4]);
/* do another action so that the undoable action
* for last file no longer exists */
track_create_with_action (
TRACK_TYPE_MIDI, NULL, NULL, PLAYHEAD,
num_tracks_before, 1, NULL);
/* save the project to remove unused files from
* pool */
test_project_save_and_reload ();
/* assert first and previous last clip are
* removed */
g_assert_cmpint (
AUDIO_POOL->num_clips, ==,
ZRYTHM->undo_stack_len + 5);
g_assert_null (AUDIO_POOL->clips[0]);
g_assert_false (g_file_test (
clip_path, G_FILE_TEST_EXISTS));
g_assert_nonnull (AUDIO_POOL->clips[1]);
g_assert_null (
AUDIO_POOL
->clips[ZRYTHM->undo_stack_len + 4]);
g_assert_nonnull (
AUDIO_POOL
->clips[ZRYTHM->undo_stack_len + 5]);
g_assert_true (g_file_test (
clip_path2, G_FILE_TEST_EXISTS));
g_assert_false (g_file_test (
last_clip_path, G_FILE_TEST_EXISTS));
test_helper_zrythm_cleanup ();
}
/* assert all clips still exist */
g_assert_cmpint (
AUDIO_POOL->num_clips, ==,
ZRYTHM->undo_stack_len + 5);
AudioClip * clip = AUDIO_POOL->clips[0];
char * clip_path = audio_clip_get_path_in_pool (
clip, F_NOT_BACKUP);
g_assert_true (
g_file_test (clip_path, G_FILE_TEST_EXISTS));
AudioClip * clip2 = AUDIO_POOL->clips[1];
char * clip_path2 = audio_clip_get_path_in_pool (
clip2, F_NOT_BACKUP);
g_assert_true (
g_file_test (clip_path2, G_FILE_TEST_EXISTS));
AudioClip * last_clip =
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 4];
char * last_clip_path =
audio_clip_get_path_in_pool (
last_clip, F_NOT_BACKUP);
g_assert_true (g_file_test (
last_clip_path, G_FILE_TEST_EXISTS));
char * undo_manager_yaml = yaml_serialize (
UNDO_MANAGER, &undo_manager_schema);
g_message ("\n%s", undo_manager_yaml);
/* undo and check that last file still exists */
undo_manager_undo (UNDO_MANAGER, NULL);
g_assert_true (g_file_test (
last_clip_path, G_FILE_TEST_EXISTS));
g_assert_cmpint (
AUDIO_POOL->num_clips, ==,
ZRYTHM->undo_stack_len + 5);
g_assert_nonnull (
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 4]);
/* do another action so that the undoable action
* for last file no longer exists */
track_create_with_action (
TRACK_TYPE_MIDI, NULL, NULL, PLAYHEAD,
num_tracks_before, 1, NULL);
/* save the project to remove unused files from
* pool */
test_project_save_and_reload ();
/* assert first and previous last clip are
* removed */
g_assert_cmpint (
AUDIO_POOL->num_clips, ==,
ZRYTHM->undo_stack_len + 5);
g_assert_null (AUDIO_POOL->clips[0]);
g_assert_false (
g_file_test (clip_path, G_FILE_TEST_EXISTS));
g_assert_nonnull (AUDIO_POOL->clips[1]);
g_assert_null (
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 4]);
g_assert_nonnull (
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 5]);
g_assert_true (
g_file_test (clip_path2, G_FILE_TEST_EXISTS));
g_assert_false (g_file_test (
last_clip_path, G_FILE_TEST_EXISTS));
test_helper_zrythm_cleanup ();
}
int

20
tests/helpers/project.h

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/**
* \file

5
tests/project.c

@ -46,7 +46,8 @@ test_empty_save_load (void) @@ -46,7 +46,8 @@ test_empty_save_load (void)
/* resave it */
ret = project_save (
PROJECT, PROJECT->dir, 0, 0, F_NO_ASYNC);
PROJECT, PROJECT->dir, F_NOT_BACKUP, 0,
F_NO_ASYNC);
g_assert_cmpint (ret, ==, 0);
test_helper_zrythm_cleanup ();
@ -206,7 +207,7 @@ test_save_backup_w_pool_and_plugins (void) @@ -206,7 +207,7 @@ test_save_backup_w_pool_and_plugins (void)
/* load the backup directly */
char * filepath = g_build_filename (
backup_dir, "project.zpj", NULL);
backup_dir, PROJECT_FILE, NULL);
ret = project_load (filepath, false);
g_free (filepath);
g_assert_cmpint (ret, ==, 0);

Loading…
Cancel
Save