mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Add pg_string_endswith as the start of a string helper library in src/common.
Backpatch to 9.3 where src/common was introduce, because a bugfix that needs to be backpatched, requires the function. Earlier branches will have to duplicate the code.
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "access/transam.h"
|
||||
#include "common/string.h"
|
||||
#include "miscadmin.h"
|
||||
#include "replication/slot.h"
|
||||
#include "storage/fd.h"
|
||||
@@ -779,24 +780,6 @@ CheckSlotRequirements(void)
|
||||
errmsg("replication slots can only be used if wal_level >= archive")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns whether the string `str' has the postfix `end'.
|
||||
*/
|
||||
static bool
|
||||
string_endswith(const char *str, const char *end)
|
||||
{
|
||||
size_t slen = strlen(str);
|
||||
size_t elen = strlen(end);
|
||||
|
||||
/* can't be a postfix if longer */
|
||||
if (elen > slen)
|
||||
return false;
|
||||
|
||||
/* compare the end of the strings */
|
||||
str += slen - elen;
|
||||
return strcmp(str, end) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush all replication slots to disk.
|
||||
*
|
||||
@@ -864,7 +847,7 @@ StartupReplicationSlots(void)
|
||||
continue;
|
||||
|
||||
/* we crashed while a slot was being setup or deleted, clean up */
|
||||
if (string_endswith(replication_de->d_name, ".tmp"))
|
||||
if (pg_str_endswith(replication_de->d_name, ".tmp"))
|
||||
{
|
||||
if (!rmtree(path, true))
|
||||
{
|
||||
|
Reference in New Issue
Block a user