8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:43:02 +01:00

Fixed issues related to encoding of switch value in gbak/nbackup - thanks to Adriano. Added support for -SKIP_DATA to services.

This commit is contained in:
alexpeshkoff 2014-05-21 13:11:43 +00:00
parent 26853e6ac6
commit befcba7105
12 changed files with 58 additions and 20 deletions

View File

@ -1287,7 +1287,7 @@ int gbak(Firebird::UtilSvc* uSvc)
if (exit_code != FINI_OK &&
(tdgbl->action->act_action == ACT_backup_split || tdgbl->action->act_action == ACT_backup))
{
unlink_platf(file->fil_name.c_str());
unlink_platf(tdgbl->toSystem(file->fil_name).c_str());
}
}
}
@ -1888,12 +1888,12 @@ static gbak_action open_files(const TEXT* file1,
}
else
{
Firebird::string nm = tdgbl->toSystem(fil->fil_name);
#ifdef WIN_NT
if ((fil->fil_fd = MVOL_open(fil->fil_name.c_str(), MODE_WRITE, CREATE_ALWAYS)) ==
if ((fil->fil_fd = MVOL_open(nm.c_str(), MODE_WRITE, CREATE_ALWAYS)) ==
INVALID_HANDLE_VALUE)
#else
if ((fil->fil_fd = open(fil->fil_name.c_str(), MODE_WRITE, open_mask)) == -1)
if ((fil->fil_fd = open(nm.c_str(), MODE_WRITE, open_mask)) == -1)
#endif // WIN_NT
{
@ -1996,11 +1996,12 @@ static gbak_action open_files(const TEXT* file1,
tdgbl->stdIoMode = false;
// open first file
Firebird::string nm = tdgbl->toSystem(fil->fil_name);
#ifdef WIN_NT
if ((fil->fil_fd = MVOL_open(fil->fil_name.c_str(), MODE_READ, OPEN_EXISTING)) ==
if ((fil->fil_fd = MVOL_open(nm.c_str(), MODE_READ, OPEN_EXISTING)) ==
INVALID_HANDLE_VALUE)
#else
if ((fil->fil_fd = open(fil->fil_name.c_str(), MODE_READ)) == INVALID_HANDLE_VALUE)
if ((fil->fil_fd = open(nm.c_str(), MODE_READ)) == INVALID_HANDLE_VALUE)
#endif
{
BURP_error(65, true, fil->fil_name.c_str());
@ -2044,11 +2045,12 @@ static gbak_action open_files(const TEXT* file1,
return QUIT;
}
tdgbl->action->act_file = fil;
Firebird::string nm = tdgbl->toSystem(fil->fil_name);
#ifdef WIN_NT
if ((fil->fil_fd = MVOL_open(fil->fil_name.c_str(), MODE_READ, OPEN_EXISTING)) ==
if ((fil->fil_fd = MVOL_open(nm.c_str(), MODE_READ, OPEN_EXISTING)) ==
INVALID_HANDLE_VALUE)
#else
if ((fil->fil_fd = open(fil->fil_name.c_str(), MODE_READ)) == INVALID_HANDLE_VALUE)
if ((fil->fil_fd = open(nm.c_str(), MODE_READ)) == INVALID_HANDLE_VALUE)
#endif
{
BURP_error(65, false, fil->fil_name.c_str());
@ -2385,7 +2387,8 @@ void BurpGlobals::setupSkipData(const Firebird::string& regexp)
if (regexp.hasData())
{
Firebird::string filter(regexp);
ISC_systemToUtf8(filter);
if (!uSvc->utf8FileNames())
ISC_systemToUtf8(filter);
skipDataMatcher.reset(new Firebird::SimilarToMatcher<UCHAR, Jrd::UpcaseConverter<> >(
*getDefaultMemoryPool(), textType, (const UCHAR*) filter.c_str(),
@ -2399,6 +2402,14 @@ void BurpGlobals::setupSkipData(const Firebird::string& regexp)
}
}
Firebird::string BurpGlobals::toSystem(const Firebird::PathName& from)
{
Firebird::string to = from.ToString();
if (uSvc->utf8FileNames())
ISC_utf8ToSystem(to);
return to;
}
bool BurpGlobals::skipRelation(const char* name)
{
if (gbl_sw_meta)
@ -2411,11 +2422,8 @@ bool BurpGlobals::skipRelation(const char* name)
return false;
}
Firebird::string utf8(name);
ISC_systemToUtf8(utf8);
skipDataMatcher->reset();
skipDataMatcher->process((const UCHAR*) (utf8.c_str()), utf8.length());
skipDataMatcher->process(reinterpret_cast<const UCHAR*>(name), strlen(name));
return skipDataMatcher->result();
}

View File

@ -1084,6 +1084,9 @@ public:
bool stdIoMode; // stdin or stdout is used as backup file
UnicodeCollationHolder unicodeCollation;
Firebird::AutoPtr<Firebird::SimilarToMatcher<UCHAR, Jrd::UpcaseConverter<> > > skipDataMatcher;
public:
Firebird::string toSystem(const Firebird::PathName& from);
};
// CVC: This aux routine declared here to not force inclusion of burp.h with burp_proto.h

View File

@ -165,7 +165,7 @@ static const Switches::in_sw_tab_t reference_burp_in_sw_table[] =
{IN_SW_BURP_S, 0, "SKIP_BAD_DATA", 0, 0, 0, false, 0, 4, NULL, boRestore},
{IN_SW_BURP_SE, 0, "SERVICE", 0, 0, 0, false, 277, 2, NULL, boGeneral},
// msg 277: @1SE(RVICE) use services manager
{IN_SW_BURP_SKIP_DATA, 0, "SKIP_DATA", 0, 0, 0, false, 355, 6, NULL, boGeneral},
{IN_SW_BURP_SKIP_DATA, isc_spb_res_skip_data, "SKIP_DATA", 0, 0, 0, false, 355, 6, NULL, boGeneral},
// msg 355: @1SKIP_DATA skip data for table
{IN_SW_BURP_T, 0, "TRANSPORTABLE", 0, 0, 0, false, 175, 1, NULL, boBackup},
// msg 175: @1TRANSPORTABLE transportable backup -- data in XDR format

View File

@ -1365,9 +1365,10 @@ bool MVOL_split_hdr_write()
time_t seconds = time(NULL);
Firebird::string nm = tdgbl->toSystem(tdgbl->action->act_file->fil_name);
sprintf(buffer, "%s%.24s , file No. %4d of %4d, %-27.27s",
HDR_SPLIT_TAG, ctime(&seconds), tdgbl->action->act_file->fil_seq,
tdgbl->action->act_total, tdgbl->action->act_file->fil_name.c_str());
tdgbl->action->act_total, nm.c_str());
#ifdef WIN_NT
DWORD bytes_written = 0;

View File

@ -229,6 +229,7 @@ IntlParametersBlock::TagType IntlSpbStart::checkTag(UCHAR tag)
switch (tag)
{
case isc_spb_bkp_file:
case isc_spb_bkp_skip_data:
return TAG_STRING;
}
break;

View File

@ -140,8 +140,9 @@ public:
virtual void setServiceStatus(const USHORT, const USHORT, const MsgFormat::SafeArg&) { }
virtual const ISC_STATUS* getStatus() { return 0; }
virtual void fillDpb(ClumpletWriter&) { }
virtual bool finished() { return false; };
virtual bool finished() { return false; }
virtual void initStatus() { }
virtual bool utf8FileNames() { return false; }
};

View File

@ -72,6 +72,7 @@ public:
virtual void fillDpb(Firebird::ClumpletWriter& dpb) = 0;
virtual bool finished() = 0;
virtual unsigned int getAuthBlock(const unsigned char** bytes) = 0;
virtual bool utf8FileNames() = 0;
void setDataMode(bool value)
{

View File

@ -379,6 +379,7 @@
#define isc_spb_bkp_file 5
#define isc_spb_bkp_factor 6
#define isc_spb_bkp_length 7
#define isc_spb_bkp_skip_data 8
#define isc_spb_bkp_ignore_checksums 0x01
#define isc_spb_bkp_ignore_limbo 0x02
#define isc_spb_bkp_metadata_only 0x04
@ -477,6 +478,7 @@
* Parameters for isc_action_svc_restore *
*****************************************/
#define isc_spb_res_skip_data isc_spb_bkp_skip_data
#define isc_spb_res_buffers 9
#define isc_spb_res_page_size 10
#define isc_spb_res_length 11

View File

@ -688,6 +688,11 @@ void Service::fillDpb(ClumpletWriter& dpb)
}
}
bool Service::utf8FileNames()
{
return svc_utf8;
}
void Service::need_admin_privs(Arg::StatusVector& status, const char* message)
{
status << Arg::Gds(isc_insufficient_svc_privileges) << Arg::Str(message);

View File

@ -147,6 +147,8 @@ public: // utilities interface with service
virtual void checkService();
// add address path and utf8 flag (taken from spb) to dpb if present
virtual void fillDpb(Firebird::ClumpletWriter& dpb);
// encoding for string parameters passed to utility
virtual bool utf8FileNames();
virtual TraceManager* getTraceManager()
{

View File

@ -346,6 +346,7 @@ const SvcSwitches backupOptions[] =
{"bkp_convert", putOption, 0, isc_spb_bkp_convert, 0},
{"bkp_no_triggers", putOption, 0, isc_spb_bkp_no_triggers, 0},
{"verbint", putNumericArgument, 0, isc_spb_verbint, 0},
{"bkp_skip_data", putStringArgument, 0, isc_spb_bkp_skip_data, 0},
{0, 0, 0, 0, 0}
};
@ -369,6 +370,7 @@ const SvcSwitches restoreOptions[] =
{"res_fix_fss_metadata", putStringArgument, 0, isc_spb_res_fix_fss_metadata, 0},
{"res_metadata_only", putOption, 0, isc_spb_res_metadata_only, 0},
{"verbint", putNumericArgument, 0, isc_spb_verbint, 0},
{"res_skip_data", putStringArgument, 0, isc_spb_res_skip_data, 0},
{0, 0, 0, 0, 0}
};

View File

@ -343,6 +343,7 @@ private:
void internal_unlock_database();
void attach_database();
void detach_database();
string to_system(const PathName& from);
// Create/open database and backup
void open_database_write();
@ -524,15 +525,25 @@ void NBackup::close_database()
#endif
}
string NBackup::to_system(const PathName& from)
{
string to = from.ToString();
if (uSvc->utf8FileNames())
ISC_utf8ToSystem(to);
return to;
}
void NBackup::open_backup_scan()
{
string nm = to_system(bakname);
#ifdef WIN_NT
backup = CreateFile(bakname.c_str(), GENERIC_READ, 0,
backup = CreateFile(nm.c_str(), GENERIC_READ, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (backup != INVALID_HANDLE_VALUE)
return;
#else
backup = open(bakname.c_str(), O_RDONLY | O_LARGEFILE);
backup = open(nm.c_str(), O_RDONLY | O_LARGEFILE);
if (backup >= 0)
return;
#endif
@ -542,13 +553,14 @@ void NBackup::open_backup_scan()
void NBackup::create_backup()
{
string nm = to_system(bakname);
#ifdef WIN_NT
if (bakname == "stdout") {
backup = GetStdHandle(STD_OUTPUT_HANDLE);
}
else
{
backup = CreateFile(bakname.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE,
backup = CreateFile(nm.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE,
NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
}
if (backup != INVALID_HANDLE_VALUE)
@ -559,7 +571,7 @@ void NBackup::create_backup()
backup = 1; // Posix file handle for stdout
return;
}
backup = open(bakname.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, 0660);
backup = open(nm.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, 0660);
if (backup >= 0)
return;
#endif