Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions src/burp/burp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,19 @@ int gbak(Firebird::UtilSvc* uSvc)

switch (in_sw_tab->in_sw)
{
case IN_SW_BURP_B:
if ((itr < argc - 1) && (*argv[itr + 1] != switch_char))
{
// find optional BURP_SW_OVERWRITE parameter
Firebird::string next(argv[itr + 1]);
next.upper();
if (strstr(BURP_SW_OVERWRITE, next.c_str()) == BURP_SW_OVERWRITE)
{
tdgbl->gbl_sw_overwrite = true;
itr++;
}
}
break;
case IN_SW_BURP_RECREATE:
{
int real_sw = IN_SW_BURP_C;
Expand Down Expand Up @@ -1162,21 +1175,23 @@ int gbak(Firebird::UtilSvc* uSvc)
Firebird::PathName expanded;
expandDatabaseName(file->fil_name, expanded, NULL);

const bool isSource = (file->fil_name.c_str() == file1);

for (file_list = file->fil_next; file_list;
file_list = file_list->fil_next)
{
if (file->fil_name == file_list->fil_name || expanded == file_list->fil_name)
{
BURP_error(9, true);
// msg 9 mutiple sources or destinations specified
}

Firebird::PathName expanded2;
expandDatabaseName(file_list->fil_name, expanded2, NULL);
if (file->fil_name == expanded2 || expanded == expanded2)

if (file->fil_name == file_list->fil_name || expanded == file_list->fil_name ||
file->fil_name == expanded2 || expanded == expanded2)
{
BURP_error(9, true);
// msg 9 mutiple sources or destinations specified
if (isSource)
BURP_error(11, true);
// msg 11 input and output have the same name. Disallowed.
else
BURP_error(9, true);
// msg 9 mutiple sources or destinations specified
}
}

Expand Down Expand Up @@ -2216,15 +2231,29 @@ static gbak_action open_files(const TEXT* file1,
{
Firebird::string nm = tdgbl->toSystem(fil->fil_name);
#ifdef WIN_NT
if ((fil->fil_fd = NT_tape_open(nm.c_str(), MODE_WRITE, CREATE_ALWAYS)) == INVALID_HANDLE_VALUE)
if ((fil->fil_fd = NT_tape_open(nm.c_str(), MODE_WRITE,
tdgbl->gbl_sw_overwrite ? CREATE_ALWAYS : CREATE_NEW)) == INVALID_HANDLE_VALUE)
#else
const int wmode = MODE_WRITE | (tdgbl->gbl_sw_direct_io ? O_DIRECT : 0);
const int wmode = MODE_WRITE
| (tdgbl->gbl_sw_direct_io ? O_DIRECT : 0)
| (tdgbl->gbl_sw_overwrite ? 0 : O_EXCL);
if ((fil->fil_fd = open(fil->fil_name.c_str(), wmode, open_mask)) == -1)
#endif // WIN_NT
{

BURP_error(65, false, fil->fil_name.c_str());
// msg 65 can't open backup file %s
#ifdef WIN_NT
if (GetLastError() == ERROR_FILE_EXISTS)
#else
if (errno == EEXIST)
#endif // WIN_NT
{
BURP_error(423, false, fil->fil_name.c_str());
// msg 423 backup file %s already exists, use OVERWRITE to replace
}
else
{
BURP_error(65, false, fil->fil_name.c_str());
// msg 65 can't open backup file %s
}
flag = QUIT;
break;
}
Expand Down
27 changes: 24 additions & 3 deletions src/burp/mvol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,17 +1548,38 @@ static DESC next_volume( DESC handle, ULONG mode, bool full_buffer)
prompt_for_name(new_file, sizeof(new_file));

#ifdef WIN_NT
new_desc = NT_tape_open(new_file, mode, OPEN_ALWAYS);
if (mode == MODE_WRITE)
{
new_desc = NT_tape_open(new_file, mode,
tdgbl->gbl_sw_overwrite ? CREATE_ALWAYS : CREATE_NEW);
}
else
new_desc = NT_tape_open(new_file, mode, OPEN_ALWAYS);
if (new_desc == INVALID_HANDLE_VALUE)
#else
ULONG mode2 = mode;
if (mode == MODE_WRITE && tdgbl->gbl_sw_direct_io)
mode2 |= O_DIRECT;
if (mode == MODE_WRITE)
{
if (tdgbl->gbl_sw_direct_io)
mode2 |= O_DIRECT;
if (!tdgbl->gbl_sw_overwrite)
mode2 |= O_EXCL;
}

new_desc = open(new_file, mode2, open_mask);
if (new_desc < 0)
#endif // WIN_NT
{
#ifdef WIN_NT
if (mode == MODE_WRITE && GetLastError() == ERROR_FILE_EXISTS)
#else
if (mode == MODE_WRITE && errno == EEXIST)
#endif // WIN_NT
{
BURP_print(true, 423, new_file);
// msg 423 backup file %s already exists, use OVERWRITE to replace
continue;
}
BURP_print(true, 222, new_file);
// msg 222 \n\nCould not open file name \"%s\"\n
continue;
Expand Down
1 change: 1 addition & 0 deletions src/include/firebird/impl/msg/gbak.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,4 @@ FB_IMPL_MSG_NO_SYMBOL(GBAK, 419, "regular expression to skip schemas was already
FB_IMPL_MSG_NO_SYMBOL(GBAK, 420, "regular expression to include schemas was already set")
FB_IMPL_MSG_SYMBOL(GBAK, 421, gbak_plugin_schema_migration, "migrating @1 plugin objects to schema @2")
FB_IMPL_MSG_SYMBOL(GBAK, 422, gbak_plugin_schema_migration_err, "error migrating @1 plugin objects to schema @2. Plugin objects will be in inconsistent state:")
FB_IMPL_MSG(GBAK, 423, gbak_backup_file_exists, -901, "00", "000", "backup file @1 already exists, use OVERWRITE to replace")