mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-03-03 14:52:21 +02:00
Update storage (except remote) module to recent coding standards.
Add const as appropriate and avoid initializing variables if the variable will definitely be set later on. The storage/remote module will be updated with the protocol module once a major waiting refactor has been committed.
This commit is contained in:
parent
76bcb740b6
commit
bb8988b551
@ -71,7 +71,7 @@ storageReadAzureOpen(THIS_VOID)
|
||||
Read from a file
|
||||
***********************************************************************************************************************************/
|
||||
static size_t
|
||||
storageReadAzure(THIS_VOID, Buffer *buffer, bool block)
|
||||
storageReadAzure(THIS_VOID, Buffer *const buffer, const bool block)
|
||||
{
|
||||
THIS(StorageReadAzure);
|
||||
|
||||
|
@ -80,7 +80,8 @@ Based on the documentation at https://docs.microsoft.com/en-us/rest/api/storages
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageAzureAuth(
|
||||
StorageAzure *this, const String *verb, const String *path, HttpQuery *query, const String *dateTime, HttpHeader *httpHeader)
|
||||
StorageAzure *const this, const String *const verb, const String *const path, HttpQuery *const query,
|
||||
const String *const dateTime, HttpHeader *const httpHeader)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_AZURE, this);
|
||||
@ -111,12 +112,12 @@ storageAzureAuth(
|
||||
httpHeaderPut(httpHeader, AZURE_HEADER_VERSION_STR, AZURE_HEADER_VERSION_VALUE_STR);
|
||||
|
||||
// Generate canonical headers
|
||||
String *headerCanonical = strNew();
|
||||
StringList *headerKeyList = httpHeaderList(httpHeader);
|
||||
String *const headerCanonical = strNew();
|
||||
const StringList *const headerKeyList = httpHeaderList(httpHeader);
|
||||
|
||||
for (unsigned int headerKeyIdx = 0; headerKeyIdx < strLstSize(headerKeyList); headerKeyIdx++)
|
||||
{
|
||||
const String *headerKey = strLstGet(headerKeyList, headerKeyIdx);
|
||||
const String *const headerKey = strLstGet(headerKeyList, headerKeyIdx);
|
||||
|
||||
if (!strBeginsWithZ(headerKey, "x-ms-"))
|
||||
continue;
|
||||
@ -125,27 +126,27 @@ storageAzureAuth(
|
||||
}
|
||||
|
||||
// Generate canonical query
|
||||
String *queryCanonical = strNew();
|
||||
String *const queryCanonical = strNew();
|
||||
|
||||
if (query != NULL)
|
||||
{
|
||||
StringList *queryKeyList = httpQueryList(query);
|
||||
const StringList *const queryKeyList = httpQueryList(query);
|
||||
ASSERT(!strLstEmpty(queryKeyList));
|
||||
|
||||
for (unsigned int queryKeyIdx = 0; queryKeyIdx < strLstSize(queryKeyList); queryKeyIdx++)
|
||||
{
|
||||
const String *queryKey = strLstGet(queryKeyList, queryKeyIdx);
|
||||
const String *const queryKey = strLstGet(queryKeyList, queryKeyIdx);
|
||||
|
||||
strCatFmt(queryCanonical, "\n%s:%s", strZ(queryKey), strZ(httpQueryGet(query, queryKey)));
|
||||
}
|
||||
}
|
||||
|
||||
// Generate string to sign
|
||||
const String *contentLength = httpHeaderGet(httpHeader, HTTP_HEADER_CONTENT_LENGTH_STR);
|
||||
const String *contentMd5 = httpHeaderGet(httpHeader, HTTP_HEADER_CONTENT_MD5_STR);
|
||||
const String *const contentLength = httpHeaderGet(httpHeader, HTTP_HEADER_CONTENT_LENGTH_STR);
|
||||
const String *const contentMd5 = httpHeaderGet(httpHeader, HTTP_HEADER_CONTENT_MD5_STR);
|
||||
const String *const range = httpHeaderGet(httpHeader, HTTP_HEADER_RANGE_STR);
|
||||
|
||||
const String *stringToSign = strNewFmt(
|
||||
const String *const stringToSign = strNewFmt(
|
||||
"%s\n" // verb
|
||||
"\n" // content-encoding
|
||||
"\n" // content-language
|
||||
@ -185,7 +186,7 @@ storageAzureAuth(
|
||||
Process Azure request
|
||||
***********************************************************************************************************************************/
|
||||
FN_EXTERN HttpRequest *
|
||||
storageAzureRequestAsync(StorageAzure *this, const String *verb, StorageAzureRequestAsyncParam param)
|
||||
storageAzureRequestAsync(StorageAzure *const this, const String *const verb, StorageAzureRequestAsyncParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_AZURE, this);
|
||||
@ -232,7 +233,7 @@ storageAzureRequestAsync(StorageAzure *this, const String *verb, StorageAzureReq
|
||||
const String *const path = httpUriEncode(param.path, true);
|
||||
|
||||
// Make a copy of the query so it can be modified
|
||||
HttpQuery *query =
|
||||
HttpQuery *const query =
|
||||
this->sasKey != NULL && param.query == NULL ?
|
||||
httpQueryNewP(.redactList = this->queryRedactList) :
|
||||
httpQueryDupP(param.query, .redactList = this->queryRedactList);
|
||||
@ -254,7 +255,7 @@ storageAzureRequestAsync(StorageAzure *this, const String *verb, StorageAzureReq
|
||||
}
|
||||
|
||||
FN_EXTERN HttpResponse *
|
||||
storageAzureResponse(HttpRequest *request, StorageAzureResponseParam param)
|
||||
storageAzureResponse(HttpRequest *const request, const StorageAzureResponseParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(HTTP_REQUEST, request);
|
||||
@ -284,7 +285,7 @@ storageAzureResponse(HttpRequest *request, StorageAzureResponseParam param)
|
||||
}
|
||||
|
||||
FN_EXTERN HttpResponse *
|
||||
storageAzureRequest(StorageAzure *this, const String *verb, StorageAzureRequestParam param)
|
||||
storageAzureRequest(StorageAzure *const this, const String *const verb, const StorageAzureRequestParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_AZURE, this);
|
||||
@ -312,8 +313,8 @@ General function for listing files to be used by other list routines
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageAzureListInternal(
|
||||
StorageAzure *this, const String *path, StorageInfoLevel level, const String *expression, bool recurse,
|
||||
StorageListCallback callback, void *callbackData)
|
||||
StorageAzure *const this, const String *const path, const StorageInfoLevel level, const String *const expression,
|
||||
const bool recurse, const StorageListCallback callback, void *const callbackData)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_AZURE, this);
|
||||
@ -333,15 +334,10 @@ storageAzureListInternal(
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Build the base prefix by stripping off the initial /
|
||||
const String *basePrefix;
|
||||
|
||||
if (strSize(path) == 1)
|
||||
basePrefix = EMPTY_STR;
|
||||
else
|
||||
basePrefix = strNewFmt("%s/", strZ(strSub(path, 1)));
|
||||
const String *const basePrefix = strSize(path) == 1 ? EMPTY_STR : strNewFmt("%s/", strZ(strSub(path, 1)));
|
||||
|
||||
// Get the expression prefix when possible to limit initial results
|
||||
const String *expressionPrefix = regExpPrefix(expression);
|
||||
const String *const expressionPrefix = regExpPrefix(expression);
|
||||
|
||||
// If there is an expression prefix then use it to build the query prefix, otherwise query prefix is base prefix
|
||||
const String *queryPrefix;
|
||||
@ -357,7 +353,7 @@ storageAzureListInternal(
|
||||
}
|
||||
|
||||
// Create query
|
||||
HttpQuery *query = httpQueryNewP();
|
||||
HttpQuery *const query = httpQueryNewP();
|
||||
|
||||
// Add the delimiter to not recurse
|
||||
if (!recurse)
|
||||
@ -396,10 +392,11 @@ storageAzureListInternal(
|
||||
else
|
||||
response = storageAzureRequestP(this, HTTP_VERB_GET_STR, .query = query);
|
||||
|
||||
XmlNode *xmlRoot = xmlDocumentRoot(xmlDocumentNewBuf(httpResponseContent(response)));
|
||||
const XmlNode *const xmlRoot = xmlDocumentRoot(xmlDocumentNewBuf(httpResponseContent(response)));
|
||||
|
||||
// If a continuation marker exists then send an async request to get more data
|
||||
const String *continuationMarker = xmlNodeContent(xmlNodeChild(xmlRoot, AZURE_XML_TAG_NEXT_MARKER_STR, false));
|
||||
const String *const continuationMarker = xmlNodeContent(
|
||||
xmlNodeChild(xmlRoot, AZURE_XML_TAG_NEXT_MARKER_STR, false));
|
||||
|
||||
if (!strEq(continuationMarker, EMPTY_STR))
|
||||
{
|
||||
@ -414,12 +411,12 @@ storageAzureListInternal(
|
||||
}
|
||||
|
||||
// Get prefix list
|
||||
XmlNode *blobs = xmlNodeChild(xmlRoot, AZURE_XML_TAG_BLOBS_STR, true);
|
||||
XmlNodeList *blobPrefixList = xmlNodeChildList(blobs, AZURE_XML_TAG_BLOB_PREFIX_STR);
|
||||
const XmlNode *const blobs = xmlNodeChild(xmlRoot, AZURE_XML_TAG_BLOBS_STR, true);
|
||||
const XmlNodeList *const blobPrefixList = xmlNodeChildList(blobs, AZURE_XML_TAG_BLOB_PREFIX_STR);
|
||||
|
||||
for (unsigned int blobPrefixIdx = 0; blobPrefixIdx < xmlNodeLstSize(blobPrefixList); blobPrefixIdx++)
|
||||
{
|
||||
const XmlNode *subPathNode = xmlNodeLstGet(blobPrefixList, blobPrefixIdx);
|
||||
const XmlNode *const subPathNode = xmlNodeLstGet(blobPrefixList, blobPrefixIdx);
|
||||
|
||||
// Get path name
|
||||
StorageInfo info =
|
||||
@ -441,11 +438,11 @@ storageAzureListInternal(
|
||||
}
|
||||
|
||||
// Get file list
|
||||
XmlNodeList *fileList = xmlNodeChildList(blobs, AZURE_XML_TAG_BLOB_STR);
|
||||
const XmlNodeList *const fileList = xmlNodeChildList(blobs, AZURE_XML_TAG_BLOB_STR);
|
||||
|
||||
for (unsigned int fileIdx = 0; fileIdx < xmlNodeLstSize(fileList); fileIdx++)
|
||||
{
|
||||
const XmlNode *fileNode = xmlNodeLstGet(fileList, fileIdx);
|
||||
const XmlNode *const fileNode = xmlNodeLstGet(fileList, fileIdx);
|
||||
|
||||
// Get file name
|
||||
StorageInfo info =
|
||||
@ -462,7 +459,7 @@ storageAzureListInternal(
|
||||
// Add basic info if requested (no need to add type info since file is default type)
|
||||
if (level >= storageInfoLevelBasic)
|
||||
{
|
||||
XmlNode *property = xmlNodeChild(fileNode, AZURE_XML_TAG_PROPERTIES_STR, true);
|
||||
const XmlNode *const property = xmlNodeChild(fileNode, AZURE_XML_TAG_PROPERTIES_STR, true);
|
||||
|
||||
info.size = cvtZToUInt64(
|
||||
strZ(xmlNodeContent(xmlNodeChild(property, AZURE_XML_TAG_CONTENT_LENGTH_STR, true))));
|
||||
@ -485,7 +482,7 @@ storageAzureListInternal(
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageInfo
|
||||
storageAzureInfo(THIS_VOID, const String *file, StorageInfoLevel level, StorageInterfaceInfoParam param)
|
||||
storageAzureInfo(THIS_VOID, const String *const file, const StorageInfoLevel level, const StorageInterfaceInfoParam param)
|
||||
{
|
||||
THIS(StorageAzure);
|
||||
|
||||
@ -558,7 +555,7 @@ storageAzureList(THIS_VOID, const String *const path, const StorageInfoLevel lev
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageRead *
|
||||
storageAzureNewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageInterfaceNewReadParam param)
|
||||
storageAzureNewRead(THIS_VOID, const String *const file, const bool ignoreMissing, const StorageInterfaceNewReadParam param)
|
||||
{
|
||||
THIS(StorageAzure);
|
||||
|
||||
@ -578,7 +575,7 @@ storageAzureNewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageIn
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageWrite *
|
||||
storageAzureNewWrite(THIS_VOID, const String *file, StorageInterfaceNewWriteParam param)
|
||||
storageAzureNewWrite(THIS_VOID, const String *const file, const StorageInterfaceNewWriteParam param)
|
||||
{
|
||||
THIS(StorageAzure);
|
||||
|
||||
@ -644,7 +641,7 @@ storageAzurePathRemoveCallback(void *const callbackData, const StorageInfo *cons
|
||||
}
|
||||
|
||||
static bool
|
||||
storageAzurePathRemove(THIS_VOID, const String *path, bool recurse, StorageInterfacePathRemoveParam param)
|
||||
storageAzurePathRemove(THIS_VOID, const String *const path, const bool recurse, const StorageInterfacePathRemoveParam param)
|
||||
{
|
||||
THIS(StorageAzure);
|
||||
|
||||
@ -680,7 +677,7 @@ storageAzurePathRemove(THIS_VOID, const String *path, bool recurse, StorageInter
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static void
|
||||
storageAzureRemove(THIS_VOID, const String *file, StorageInterfaceRemoveParam param)
|
||||
storageAzureRemove(THIS_VOID, const String *const file, const StorageInterfaceRemoveParam param)
|
||||
{
|
||||
THIS(StorageAzure);
|
||||
|
||||
|
@ -84,7 +84,7 @@ storageWriteAzureOpen(THIS_VOID)
|
||||
Flush bytes to upload block
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageWriteAzureBlock(StorageWriteAzure *this)
|
||||
storageWriteAzureBlock(StorageWriteAzure *const this)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(STORAGE_WRITE_AZURE, this);
|
||||
@ -105,7 +105,7 @@ storageWriteAzureBlock(StorageWriteAzure *this)
|
||||
}
|
||||
|
||||
static void
|
||||
storageWriteAzureBlockAsync(StorageWriteAzure *this)
|
||||
storageWriteAzureBlockAsync(StorageWriteAzure *const this)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(STORAGE_WRITE_AZURE, this);
|
||||
@ -134,10 +134,10 @@ storageWriteAzureBlockAsync(StorageWriteAzure *this)
|
||||
// overlap with any other process. This is to prevent another process from overwriting our blocks. If two processes are
|
||||
// writing against the same file then there may be problems anyway but we need to at least ensure the result is consistent,
|
||||
// i.e. we get all of one file or all of the other depending on who writes last.
|
||||
const String *blockId = strNewFmt("%016" PRIX64 "x%07u", this->fileId, strLstSize(this->blockIdList));
|
||||
const String *const blockId = strNewFmt("%016" PRIX64 "x%07u", this->fileId, strLstSize(this->blockIdList));
|
||||
|
||||
// Upload the block and add to block list
|
||||
HttpQuery *query = httpQueryNewP();
|
||||
HttpQuery *const query = httpQueryNewP();
|
||||
httpQueryAdd(query, AZURE_QUERY_COMP_STR, AZURE_QUERY_VALUE_BLOCK_STR);
|
||||
httpQueryAdd(query, AZURE_QUERY_BLOCK_ID_STR, blockId);
|
||||
|
||||
@ -159,7 +159,7 @@ storageWriteAzureBlockAsync(StorageWriteAzure *this)
|
||||
Write to internal buffer
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageWriteAzure(THIS_VOID, const Buffer *buffer)
|
||||
storageWriteAzure(THIS_VOID, const Buffer *const buffer)
|
||||
{
|
||||
THIS(StorageWriteAzure);
|
||||
|
||||
@ -227,7 +227,7 @@ storageWriteAzureClose(THIS_VOID)
|
||||
storageWriteAzureBlock(this);
|
||||
|
||||
// Generate the xml block list
|
||||
XmlDocument *blockXml = xmlDocumentNew(AZURE_XML_TAG_BLOCK_LIST_STR);
|
||||
XmlDocument *const blockXml = xmlDocumentNew(AZURE_XML_TAG_BLOCK_LIST_STR);
|
||||
|
||||
for (unsigned int blockIdx = 0; blockIdx < strLstSize(this->blockIdList); blockIdx++)
|
||||
{
|
||||
|
@ -12,7 +12,8 @@ CIFS Storage
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN Storage *
|
||||
storageCifsNew(
|
||||
const String *path, mode_t modeFile, mode_t modePath, bool write, StoragePathExpressionCallback pathExpressionFunction)
|
||||
const String *const path, const mode_t modeFile, const mode_t modePath, const bool write,
|
||||
StoragePathExpressionCallback pathExpressionFunction)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, path);
|
||||
|
@ -78,7 +78,7 @@ storageReadGcsOpen(THIS_VOID)
|
||||
Read from a file
|
||||
***********************************************************************************************************************************/
|
||||
static size_t
|
||||
storageReadGcs(THIS_VOID, Buffer *buffer, bool block)
|
||||
storageReadGcs(THIS_VOID, Buffer *const buffer, const bool block)
|
||||
{
|
||||
THIS(StorageReadGcs);
|
||||
|
||||
|
@ -140,7 +140,7 @@ storageGcsAuthToken(HttpRequest *const request, const time_t timeBegin)
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Get the response
|
||||
KeyValue *const kvResponse = varKv(jsonToVar(strNewBuf(httpResponseContent(httpRequestResponse(request, true)))));
|
||||
const KeyValue *const kvResponse = varKv(jsonToVar(strNewBuf(httpResponseContent(httpRequestResponse(request, true)))));
|
||||
|
||||
// Check for an error
|
||||
const String *const error = varStr(kvGet(kvResponse, GCS_JSON_ERROR_VAR));
|
||||
@ -180,7 +180,7 @@ Based on the documentation at https://developers.google.com/identity/protocols/o
|
||||
***********************************************************************************************************************************/
|
||||
// Helper to construct a JSON Web Token
|
||||
static String *
|
||||
storageGcsAuthJwt(StorageGcs *this, time_t timeBegin)
|
||||
storageGcsAuthJwt(StorageGcs *const this, const time_t timeBegin)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_GCS, this);
|
||||
@ -188,12 +188,13 @@ storageGcsAuthJwt(StorageGcs *this, time_t timeBegin)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
// Static header with dot delimiter
|
||||
String *result = strCatZ(strNew(), "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.");
|
||||
String *const result = strCatZ(strNew(), "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.");
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Load client email and private key
|
||||
KeyValue *const kvKey = varKv(jsonToVar(strNewBuf(storageGetP(storageNewReadP(storagePosixNewP(FSLASH_STR), this->key)))));
|
||||
const KeyValue *const kvKey = varKv(
|
||||
jsonToVar(strNewBuf(storageGetP(storageNewReadP(storagePosixNewP(FSLASH_STR), this->key)))));
|
||||
const String *const clientEmail = varStr(kvGet(kvKey, GCS_JSON_CLIENT_EMAIL_VAR));
|
||||
const String *const privateKeyRaw = varStr(kvGet(kvKey, GCS_JSON_PRIVATE_KEY_VAR));
|
||||
|
||||
@ -236,7 +237,7 @@ storageGcsAuthJwt(StorageGcs *this, time_t timeBegin)
|
||||
size_t signatureLen = 0;
|
||||
cryptoError(EVP_DigestSignFinal((EVP_MD_CTX *)sign, NULL, &signatureLen) <= 0, "unable to get size");
|
||||
|
||||
Buffer *signature = bufNew(signatureLen);
|
||||
Buffer *const signature = bufNew(signatureLen);
|
||||
bufUsedSet(signature, bufSize(signature));
|
||||
|
||||
cryptoError(EVP_DigestSignFinal((EVP_MD_CTX *)sign, bufPtr(signature), &signatureLen) <= 0, "unable to finalize");
|
||||
@ -263,7 +264,7 @@ storageGcsAuthJwt(StorageGcs *this, time_t timeBegin)
|
||||
}
|
||||
|
||||
static StorageGcsAuthTokenResult
|
||||
storageGcsAuthService(StorageGcs *this, time_t timeBegin)
|
||||
storageGcsAuthService(StorageGcs *const this, const time_t timeBegin)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_GCS, this);
|
||||
@ -279,16 +280,16 @@ storageGcsAuthService(StorageGcs *this, time_t timeBegin)
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
String *content = strNewFmt(
|
||||
const String *const content = strNewFmt(
|
||||
"grant_type=urn%%3Aietf%%3Aparams%%3Aoauth%%3Agrant-type%%3Ajwt-bearer&assertion=%s",
|
||||
strZ(storageGcsAuthJwt(this, timeBegin)));
|
||||
|
||||
HttpHeader *header = httpHeaderNew(NULL);
|
||||
HttpHeader *const header = httpHeaderNew(NULL);
|
||||
httpHeaderAdd(header, HTTP_HEADER_HOST_STR, httpUrlHost(this->authUrl));
|
||||
httpHeaderAdd(header, HTTP_HEADER_CONTENT_TYPE_STR, HTTP_HEADER_CONTENT_TYPE_APP_FORM_URL_STR);
|
||||
httpHeaderAdd(header, HTTP_HEADER_CONTENT_LENGTH_STR, strNewFmt("%zu", strSize(content)));
|
||||
|
||||
HttpRequest *request = httpRequestNewP(
|
||||
HttpRequest *const request = httpRequestNewP(
|
||||
this->authClient, HTTP_VERB_POST_STR, httpUrlPath(this->authUrl), NULL, .header = header, .content = BUFSTR(content));
|
||||
|
||||
MEM_CONTEXT_PRIOR_BEGIN()
|
||||
@ -308,7 +309,7 @@ Get authentication token automatically for instances running in GCE.
|
||||
Based on the documentation at https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#applications
|
||||
***********************************************************************************************************************************/
|
||||
static StorageGcsAuthTokenResult
|
||||
storageGcsAuthAuto(StorageGcs *this, time_t timeBegin)
|
||||
storageGcsAuthAuto(StorageGcs *const this, const time_t timeBegin)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_GCS, this);
|
||||
@ -324,12 +325,12 @@ storageGcsAuthAuto(StorageGcs *this, time_t timeBegin)
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
HttpHeader *header = httpHeaderNew(NULL);
|
||||
HttpHeader *const header = httpHeaderNew(NULL);
|
||||
httpHeaderAdd(header, HTTP_HEADER_HOST_STR, httpUrlHost(this->authUrl));
|
||||
httpHeaderAdd(header, GCS_HEADER_METADATA_FLAVOR_STR, GCS_HEADER_GOOGLE_STR);
|
||||
httpHeaderAdd(header, HTTP_HEADER_CONTENT_LENGTH_STR, ZERO_STR);
|
||||
|
||||
HttpRequest *request = httpRequestNewP(
|
||||
HttpRequest *const request = httpRequestNewP(
|
||||
this->authClient, HTTP_VERB_GET_STR, httpUrlPath(this->authUrl), NULL, .header = header);
|
||||
|
||||
MEM_CONTEXT_PRIOR_BEGIN()
|
||||
@ -347,7 +348,7 @@ storageGcsAuthAuto(StorageGcs *this, time_t timeBegin)
|
||||
Generate authorization header and add it to the supplied header list
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageGcsAuth(StorageGcs *this, HttpHeader *httpHeader)
|
||||
storageGcsAuth(StorageGcs *const this, HttpHeader *const httpHeader)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_GCS, this);
|
||||
@ -365,12 +366,12 @@ storageGcsAuth(StorageGcs *this, HttpHeader *httpHeader)
|
||||
{
|
||||
ASSERT(this->keyType == storageGcsKeyTypeAuto || this->keyType == storageGcsKeyTypeService);
|
||||
|
||||
time_t timeBegin = time(NULL);
|
||||
const time_t timeBegin = time(NULL);
|
||||
|
||||
// If the current token has expired then request a new one
|
||||
if (timeBegin >= this->tokenTimeExpire)
|
||||
{
|
||||
StorageGcsAuthTokenResult tokenResult =
|
||||
const StorageGcsAuthTokenResult tokenResult =
|
||||
this->keyType == storageGcsKeyTypeAuto ?
|
||||
storageGcsAuthAuto(this, timeBegin) : storageGcsAuthService(this, timeBegin);
|
||||
|
||||
@ -429,7 +430,7 @@ storageGcsRequestPath(StorageGcs *const this, const String *const object, const
|
||||
}
|
||||
|
||||
FN_EXTERN HttpRequest *
|
||||
storageGcsRequestAsync(StorageGcs *this, const String *verb, StorageGcsRequestAsyncParam param)
|
||||
storageGcsRequestAsync(StorageGcs *const this, const String *const verb, StorageGcsRequestAsyncParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_GCS, this);
|
||||
@ -459,7 +460,7 @@ storageGcsRequestAsync(StorageGcs *this, const String *verb, StorageGcsRequestAs
|
||||
param.path != NULL ? param.path : storageGcsRequestPath(this, param.object, !param.noBucket, param.upload);
|
||||
|
||||
// Create header list
|
||||
HttpHeader *requestHeader =
|
||||
HttpHeader *const requestHeader =
|
||||
param.header == NULL ? httpHeaderNew(this->headerRedactList) : httpHeaderDup(param.header, this->headerRedactList);
|
||||
|
||||
// Add tags
|
||||
@ -505,7 +506,7 @@ storageGcsRequestAsync(StorageGcs *this, const String *verb, StorageGcsRequestAs
|
||||
content == NULL || bufEmpty(content) ? ZERO_STR : strNewFmt("%zu", bufUsed(content)));
|
||||
|
||||
// Make a copy of the query so it can be modified
|
||||
HttpQuery *query = httpQueryDupP(param.query, .redactList = this->queryRedactList);
|
||||
HttpQuery *const query = httpQueryDupP(param.query, .redactList = this->queryRedactList);
|
||||
|
||||
// Generate authorization header
|
||||
if (!param.noAuth)
|
||||
@ -525,7 +526,7 @@ storageGcsRequestAsync(StorageGcs *this, const String *verb, StorageGcsRequestAs
|
||||
}
|
||||
|
||||
FN_EXTERN HttpResponse *
|
||||
storageGcsResponse(HttpRequest *request, StorageGcsResponseParam param)
|
||||
storageGcsResponse(HttpRequest *const request, const StorageGcsResponseParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(HTTP_REQUEST, request);
|
||||
@ -609,7 +610,7 @@ storageGcsCvtTime(const String *const time)
|
||||
}
|
||||
|
||||
static void
|
||||
storageGcsInfoFile(StorageInfo *info, const KeyValue *file)
|
||||
storageGcsInfoFile(StorageInfo *const info, const KeyValue *const file)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_INFO, info);
|
||||
@ -624,8 +625,8 @@ storageGcsInfoFile(StorageInfo *info, const KeyValue *file)
|
||||
|
||||
static void
|
||||
storageGcsListInternal(
|
||||
StorageGcs *this, const String *path, StorageInfoLevel level, const String *expression, bool recurse,
|
||||
StorageListCallback callback, void *callbackData)
|
||||
StorageGcs *const this, const String *const path, const StorageInfoLevel level, const String *const expression,
|
||||
const bool recurse, StorageListCallback callback, void *const callbackData)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_GCS, this);
|
||||
@ -645,15 +646,10 @@ storageGcsListInternal(
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Build the base prefix by stripping off the initial /
|
||||
const String *basePrefix;
|
||||
|
||||
if (strSize(path) == 1)
|
||||
basePrefix = EMPTY_STR;
|
||||
else
|
||||
basePrefix = strNewFmt("%s/", strZ(strSub(path, 1)));
|
||||
const String *const basePrefix = strSize(path) == 1 ? EMPTY_STR : strNewFmt("%s/", strZ(strSub(path, 1)));
|
||||
|
||||
// Get the expression prefix when possible to limit initial results
|
||||
const String *expressionPrefix = regExpPrefix(expression);
|
||||
const String *const expressionPrefix = regExpPrefix(expression);
|
||||
|
||||
// If there is an expression prefix then use it to build the query prefix, otherwise query prefix is base prefix
|
||||
const String *queryPrefix;
|
||||
@ -669,7 +665,7 @@ storageGcsListInternal(
|
||||
}
|
||||
|
||||
// Create query
|
||||
HttpQuery *query = httpQueryNewP();
|
||||
HttpQuery *const query = httpQueryNewP();
|
||||
|
||||
// Add the delimiter to not recurse
|
||||
if (!recurse)
|
||||
@ -705,10 +701,10 @@ storageGcsListInternal(
|
||||
else
|
||||
response = storageGcsRequestP(this, HTTP_VERB_GET_STR, .query = query);
|
||||
|
||||
KeyValue *content = varKv(jsonToVar(strNewBuf(httpResponseContent(response))));
|
||||
const KeyValue *const content = varKv(jsonToVar(strNewBuf(httpResponseContent(response))));
|
||||
|
||||
// If next page token exists then send an async request to get more data
|
||||
const String *nextPageToken = varStr(kvGet(content, GCS_JSON_NEXT_PAGE_TOKEN_VAR));
|
||||
const String *const nextPageToken = varStr(kvGet(content, GCS_JSON_NEXT_PAGE_TOKEN_VAR));
|
||||
|
||||
if (nextPageToken != NULL)
|
||||
{
|
||||
@ -723,7 +719,7 @@ storageGcsListInternal(
|
||||
}
|
||||
|
||||
// Get prefix list
|
||||
const VariantList *prefixList = varVarLst(kvGet(content, GCS_JSON_PREFIXES_VAR));
|
||||
const VariantList *const prefixList = varVarLst(kvGet(content, GCS_JSON_PREFIXES_VAR));
|
||||
|
||||
if (prefixList != NULL)
|
||||
{
|
||||
@ -750,13 +746,13 @@ storageGcsListInternal(
|
||||
}
|
||||
|
||||
// Get file list
|
||||
const VariantList *fileList = varVarLst(kvGet(content, GCS_JSON_ITEMS_VAR));
|
||||
const VariantList *const fileList = varVarLst(kvGet(content, GCS_JSON_ITEMS_VAR));
|
||||
|
||||
if (fileList != NULL)
|
||||
{
|
||||
for (unsigned int fileIdx = 0; fileIdx < varLstSize(fileList); fileIdx++)
|
||||
{
|
||||
const KeyValue *file = varKv(varLstGet(fileList, fileIdx));
|
||||
const KeyValue *const file = varKv(varLstGet(fileList, fileIdx));
|
||||
CHECK(FormatError, file != NULL, "file missing");
|
||||
|
||||
// Get file name
|
||||
@ -879,7 +875,7 @@ storageGcsList(THIS_VOID, const String *const path, const StorageInfoLevel level
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageRead *
|
||||
storageGcsNewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageInterfaceNewReadParam param)
|
||||
storageGcsNewRead(THIS_VOID, const String *const file, const bool ignoreMissing, const StorageInterfaceNewReadParam param)
|
||||
{
|
||||
THIS(StorageGcs);
|
||||
|
||||
@ -899,7 +895,7 @@ storageGcsNewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageInte
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageWrite *
|
||||
storageGcsNewWrite(THIS_VOID, const String *file, StorageInterfaceNewWriteParam param)
|
||||
storageGcsNewWrite(THIS_VOID, const String *const file, const StorageInterfaceNewWriteParam param)
|
||||
{
|
||||
THIS(StorageGcs);
|
||||
|
||||
@ -1060,7 +1056,7 @@ storageGcsPathRemoveCallback(void *const callbackData, const StorageInfo *const
|
||||
}
|
||||
|
||||
static bool
|
||||
storageGcsPathRemove(THIS_VOID, const String *path, bool recurse, StorageInterfacePathRemoveParam param)
|
||||
storageGcsPathRemove(THIS_VOID, const String *const path, const bool recurse, const StorageInterfacePathRemoveParam param)
|
||||
{
|
||||
THIS(StorageGcs);
|
||||
|
||||
@ -1241,7 +1237,7 @@ storageGcsNew(
|
||||
}
|
||||
|
||||
// Parse the endpoint to extract the host and port
|
||||
HttpUrl *url = httpUrlNewParseP(endpoint, .type = httpProtocolTypeHttps);
|
||||
const HttpUrl *const url = httpUrlNewParseP(endpoint, .type = httpProtocolTypeHttps);
|
||||
this->endpoint = httpUrlHost(url);
|
||||
|
||||
// Create the http client used to service requests
|
||||
|
@ -151,7 +151,7 @@ storageWriteGcsBlock(StorageWriteGcs *const this, const bool done)
|
||||
}
|
||||
|
||||
static void
|
||||
storageWriteGcsBlockAsync(StorageWriteGcs *this, bool done)
|
||||
storageWriteGcsBlockAsync(StorageWriteGcs *const this, const bool done)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(STORAGE_WRITE_GCS, this);
|
||||
@ -167,7 +167,7 @@ storageWriteGcsBlockAsync(StorageWriteGcs *this, bool done)
|
||||
storageWriteGcsBlock(this, false);
|
||||
|
||||
// Build query
|
||||
HttpQuery *query = httpQueryNewP();
|
||||
HttpQuery *const query = httpQueryNewP();
|
||||
httpQueryAdd(query, GCS_QUERY_NAME_STR, strSub(this->interface.name, 1));
|
||||
httpQueryAdd(query, GCS_QUERY_UPLOAD_TYPE_STR, GCS_QUERY_RESUMABLE_STR);
|
||||
|
||||
@ -225,7 +225,7 @@ storageWriteGcsBlockAsync(StorageWriteGcs *this, bool done)
|
||||
Write to internal buffer
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageWriteGcs(THIS_VOID, const Buffer *buffer)
|
||||
storageWriteGcs(THIS_VOID, const Buffer *const buffer)
|
||||
{
|
||||
THIS(StorageWriteGcs);
|
||||
|
||||
|
@ -98,7 +98,7 @@ storageHelperInit(const StorageHelper *const helperList)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
storageHelperDryRunInit(bool dryRun)
|
||||
storageHelperDryRunInit(const bool dryRun)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
@ -176,14 +176,14 @@ storageLocalWrite(void)
|
||||
Get pg storage for the specified host id
|
||||
***********************************************************************************************************************************/
|
||||
static Storage *
|
||||
storagePgGet(unsigned int pgIdx, bool write)
|
||||
storagePgGet(const unsigned int pgIdx, const bool write)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgIdx);
|
||||
FUNCTION_TEST_PARAM(BOOL, write);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
Storage *result = NULL;
|
||||
Storage *result;
|
||||
|
||||
// Use remote storage
|
||||
if (!pgIsLocal(pgIdx))
|
||||
@ -194,16 +194,14 @@ storagePgGet(unsigned int pgIdx, bool write)
|
||||
}
|
||||
// Use Posix storage
|
||||
else
|
||||
{
|
||||
result = storagePosixNewP(cfgOptionIdxStr(cfgOptPgPath, pgIdx), .write = write);
|
||||
}
|
||||
|
||||
FUNCTION_TEST_RETURN(STORAGE, result);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN const Storage *
|
||||
storagePgIdx(unsigned int pgIdx)
|
||||
storagePgIdx(const unsigned int pgIdx)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgIdx);
|
||||
@ -234,7 +232,7 @@ storagePg(void)
|
||||
}
|
||||
|
||||
FN_EXTERN const Storage *
|
||||
storagePgIdxWrite(unsigned int pgIdx)
|
||||
storagePgIdxWrite(const unsigned int pgIdx)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, pgIdx);
|
||||
@ -349,7 +347,7 @@ storageRepoPathExpression(const String *const expression, const String *const pa
|
||||
Get the repo storage
|
||||
***********************************************************************************************************************************/
|
||||
static Storage *
|
||||
storageRepoGet(unsigned int repoIdx, bool write)
|
||||
storageRepoGet(const unsigned int repoIdx, const bool write)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, repoIdx);
|
||||
@ -398,7 +396,7 @@ storageRepoGet(unsigned int repoIdx, bool write)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN const Storage *
|
||||
storageRepoIdx(unsigned int repoIdx)
|
||||
storageRepoIdx(const unsigned int repoIdx)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, repoIdx);
|
||||
@ -437,7 +435,7 @@ storageRepo(void)
|
||||
}
|
||||
|
||||
FN_EXTERN const Storage *
|
||||
storageRepoIdxWrite(unsigned int repoIdx)
|
||||
storageRepoIdxWrite(const unsigned int repoIdx)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(UINT, repoIdx);
|
||||
@ -483,7 +481,7 @@ storageRepoWrite(void)
|
||||
Spool storage path expression
|
||||
***********************************************************************************************************************************/
|
||||
static String *
|
||||
storageSpoolPathExpression(const String *expression, const String *path)
|
||||
storageSpoolPathExpression(const String *const expression, const String *const path)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STRING, expression);
|
||||
|
@ -156,7 +156,7 @@ storageLstInsert(StorageList *const this, const unsigned int idx, const StorageI
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN StorageInfo
|
||||
storageLstGet(StorageList *const this, const unsigned int idx)
|
||||
storageLstGet(const StorageList *const this, const unsigned int idx)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_LIST, this);
|
||||
|
@ -68,7 +68,7 @@ storageLstAdd(StorageList *const this, const StorageInfo *const info)
|
||||
}
|
||||
|
||||
// Get info. Note that StorageInfo pointer members (e.g. name) will be undefined after the next call to storageLstGet().
|
||||
FN_EXTERN StorageInfo storageLstGet(StorageList *this, unsigned int idx);
|
||||
FN_EXTERN StorageInfo storageLstGet(const StorageList *this, unsigned int idx);
|
||||
|
||||
// Move to a new parent mem context
|
||||
FN_INLINE_ALWAYS StorageList *
|
||||
|
@ -106,7 +106,7 @@ storageReadPosixOpen(THIS_VOID)
|
||||
Read from a file
|
||||
***********************************************************************************************************************************/
|
||||
static size_t
|
||||
storageReadPosix(THIS_VOID, Buffer *buffer, bool block)
|
||||
storageReadPosix(THIS_VOID, Buffer *const buffer, const bool block)
|
||||
{
|
||||
THIS(StorageReadPosix);
|
||||
|
||||
|
@ -37,7 +37,7 @@ struct StoragePosix
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageInfo
|
||||
storagePosixInfo(THIS_VOID, const String *file, StorageInfoLevel level, StorageInterfaceInfoParam param)
|
||||
storagePosixInfo(THIS_VOID, const String *const file, const StorageInfoLevel level, const StorageInterfaceInfoParam param)
|
||||
{
|
||||
THIS(StoragePosix);
|
||||
|
||||
@ -269,7 +269,7 @@ storagePosixList(THIS_VOID, const String *const path, const StorageInfoLevel lev
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static bool
|
||||
storagePosixMove(THIS_VOID, StorageRead *source, StorageWrite *destination, StorageInterfaceMoveParam param)
|
||||
storagePosixMove(THIS_VOID, StorageRead *const source, StorageWrite *const destination, const StorageInterfaceMoveParam param)
|
||||
{
|
||||
THIS(StoragePosix);
|
||||
|
||||
@ -288,9 +288,9 @@ storagePosixMove(THIS_VOID, StorageRead *source, StorageWrite *destination, Stor
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
const String *sourceFile = storageReadName(source);
|
||||
const String *destinationFile = storageWriteName(destination);
|
||||
const String *destinationPath = strPath(destinationFile);
|
||||
const String *const sourceFile = storageReadName(source);
|
||||
const String *const destinationFile = storageWriteName(destination);
|
||||
const String *const destinationPath = strPath(destinationFile);
|
||||
|
||||
// Attempt to move the file
|
||||
if (rename(strZ(sourceFile), strZ(destinationFile)) == -1)
|
||||
@ -328,7 +328,7 @@ storagePosixMove(THIS_VOID, StorageRead *source, StorageWrite *destination, Stor
|
||||
// Sync source path if the destination path was synced and the paths are not equal
|
||||
if (storageWriteSyncPath(destination))
|
||||
{
|
||||
String *sourcePath = strPath(sourceFile);
|
||||
const String *const sourcePath = strPath(sourceFile);
|
||||
|
||||
if (!strEq(destinationPath, sourcePath))
|
||||
storageInterfacePathSyncP(this, sourcePath);
|
||||
@ -342,7 +342,7 @@ storagePosixMove(THIS_VOID, StorageRead *source, StorageWrite *destination, Stor
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageRead *
|
||||
storagePosixNewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageInterfaceNewReadParam param)
|
||||
storagePosixNewRead(THIS_VOID, const String *const file, const bool ignoreMissing, const StorageInterfaceNewReadParam param)
|
||||
{
|
||||
THIS(StoragePosix);
|
||||
|
||||
@ -362,7 +362,7 @@ storagePosixNewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageIn
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageWrite *
|
||||
storagePosixNewWrite(THIS_VOID, const String *file, StorageInterfaceNewWriteParam param)
|
||||
storagePosixNewWrite(THIS_VOID, const String *const file, const StorageInterfaceNewWriteParam param)
|
||||
{
|
||||
THIS(StoragePosix);
|
||||
|
||||
@ -434,7 +434,7 @@ storagePosixPathCreate(
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static bool
|
||||
storagePosixPathRemove(THIS_VOID, const String *path, bool recurse, StorageInterfacePathRemoveParam param)
|
||||
storagePosixPathRemove(THIS_VOID, const String *const path, const bool recurse, const StorageInterfacePathRemoveParam param)
|
||||
{
|
||||
THIS(StoragePosix);
|
||||
|
||||
@ -503,7 +503,7 @@ storagePosixPathRemove(THIS_VOID, const String *path, bool recurse, StorageInter
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static void
|
||||
storagePosixPathSync(THIS_VOID, const String *path, StorageInterfacePathSyncParam param)
|
||||
storagePosixPathSync(THIS_VOID, const String *const path, const StorageInterfacePathSyncParam param)
|
||||
{
|
||||
THIS(StoragePosix);
|
||||
|
||||
@ -517,7 +517,7 @@ storagePosixPathSync(THIS_VOID, const String *path, StorageInterfacePathSyncPara
|
||||
ASSERT(path != NULL);
|
||||
|
||||
// Open directory and handle errors
|
||||
int fd = open(strZ(path), O_RDONLY, 0);
|
||||
const int fd = open(strZ(path), O_RDONLY, 0);
|
||||
|
||||
// Handle errors
|
||||
if (fd == -1)
|
||||
@ -532,7 +532,7 @@ storagePosixPathSync(THIS_VOID, const String *path, StorageInterfacePathSyncPara
|
||||
// Attempt to sync the directory
|
||||
if (fsync(fd) == -1)
|
||||
{
|
||||
int errNo = errno;
|
||||
const int errNo = errno;
|
||||
|
||||
// Close the file descriptor to free resources but don't check for failure
|
||||
close(fd);
|
||||
@ -548,7 +548,7 @@ storagePosixPathSync(THIS_VOID, const String *path, StorageInterfacePathSyncPara
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static void
|
||||
storagePosixRemove(THIS_VOID, const String *file, StorageInterfaceRemoveParam param)
|
||||
storagePosixRemove(THIS_VOID, const String *const file, const StorageInterfaceRemoveParam param)
|
||||
{
|
||||
THIS(StoragePosix);
|
||||
|
||||
@ -635,7 +635,7 @@ storagePosixNewInternal(
|
||||
}
|
||||
|
||||
FN_EXTERN Storage *
|
||||
storagePosixNew(const String *path, StoragePosixNewParam param)
|
||||
storagePosixNew(const String *const path, const StoragePosixNewParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STRING, path);
|
||||
|
@ -158,7 +158,7 @@ storageWritePosixOpen(THIS_VOID)
|
||||
Write to the file
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageWritePosix(THIS_VOID, const Buffer *buffer)
|
||||
storageWritePosix(THIS_VOID, const Buffer *const buffer)
|
||||
{
|
||||
THIS(StorageWritePosix);
|
||||
|
||||
|
@ -74,7 +74,7 @@ storageReadS3Open(THIS_VOID)
|
||||
Read from a file
|
||||
***********************************************************************************************************************************/
|
||||
static size_t
|
||||
storageReadS3(THIS_VOID, Buffer *buffer, bool block)
|
||||
storageReadS3(THIS_VOID, Buffer *const buffer, const bool block)
|
||||
{
|
||||
THIS(StorageReadS3);
|
||||
|
||||
|
@ -127,7 +127,7 @@ Expected ISO-8601 data/time size
|
||||
Format ISO-8601 date/time for authentication
|
||||
***********************************************************************************************************************************/
|
||||
static String *
|
||||
storageS3DateTime(time_t authTime)
|
||||
storageS3DateTime(const time_t authTime)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(TIME, authTime);
|
||||
@ -150,8 +150,8 @@ Based on the excellent documentation at http://docs.aws.amazon.com/AmazonS3/late
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageS3Auth(
|
||||
StorageS3 *this, const String *verb, const String *path, const HttpQuery *query, const String *dateTime,
|
||||
HttpHeader *httpHeader, const String *payloadHash)
|
||||
StorageS3 *const this, const String *const verb, const String *const path, const HttpQuery *const query,
|
||||
const String *const dateTime, HttpHeader *const httpHeader, const String *const payloadHash)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE_S3, this);
|
||||
@ -172,7 +172,7 @@ storageS3Auth(
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Get date from datetime
|
||||
const String *date = strSubN(dateTime, 0, 8);
|
||||
const String *const date = strSubN(dateTime, 0, 8);
|
||||
|
||||
// Set required headers
|
||||
httpHeaderPut(httpHeader, S3_HEADER_CONTENT_SHA256_STR, payloadHash);
|
||||
@ -183,16 +183,16 @@ storageS3Auth(
|
||||
httpHeaderPut(httpHeader, S3_HEADER_TOKEN_STR, this->securityToken);
|
||||
|
||||
// Generate canonical request and signed headers
|
||||
const StringList *headerList = strLstSort(strLstDup(httpHeaderList(httpHeader)), sortOrderAsc);
|
||||
const StringList *const headerList = strLstSort(strLstDup(httpHeaderList(httpHeader)), sortOrderAsc);
|
||||
String *signedHeaders = NULL;
|
||||
|
||||
String *canonicalRequest = strCatFmt(
|
||||
String *const canonicalRequest = strCatFmt(
|
||||
strNew(), "%s\n%s\n%s\n", strZ(verb), strZ(path), query == NULL ? "" : strZ(httpQueryRenderP(query)));
|
||||
|
||||
for (unsigned int headerIdx = 0; headerIdx < strLstSize(headerList); headerIdx++)
|
||||
{
|
||||
const String *headerKey = strLstGet(headerList, headerIdx);
|
||||
const String *headerKeyLower = strLower(strDup(headerKey));
|
||||
const String *const headerKey = strLstGet(headerList, headerIdx);
|
||||
const String *const headerKeyLower = strLower(strDup(headerKey));
|
||||
|
||||
// Skip the authorization (exists on retry) and content-length headers since they do not need to be signed
|
||||
if (strEq(headerKeyLower, HTTP_HEADER_AUTHORIZATION_STR) || strEq(headerKeyLower, HTTP_HEADER_CONTENT_LENGTH_STR))
|
||||
@ -209,7 +209,7 @@ storageS3Auth(
|
||||
strCatFmt(canonicalRequest, "\n%s\n%s", strZ(signedHeaders), strZ(payloadHash));
|
||||
|
||||
// Generate string to sign
|
||||
const String *stringToSign = strNewFmt(
|
||||
const String *const stringToSign = strNewFmt(
|
||||
AWS4_HMAC_SHA256 "\n%s\n%s/%s/" S3 "/" AWS4_REQUEST "\n%s", strZ(dateTime), strZ(date), strZ(this->region),
|
||||
strZ(strNewEncode(encodingHex, cryptoHashOne(hashTypeSha256, BUFSTR(canonicalRequest)))));
|
||||
|
||||
@ -218,10 +218,10 @@ storageS3Auth(
|
||||
// If the cached signing key has expired (or has none been generated) then regenerate it
|
||||
if (!strEq(date, this->signingKeyDate))
|
||||
{
|
||||
const Buffer *dateKey = cryptoHmacOne(
|
||||
const Buffer *const dateKey = cryptoHmacOne(
|
||||
hashTypeSha256, BUFSTR(strNewFmt(AWS4 "%s", strZ(this->secretAccessKey))), BUFSTR(date));
|
||||
const Buffer *regionKey = cryptoHmacOne(hashTypeSha256, dateKey, BUFSTR(this->region));
|
||||
const Buffer *serviceKey = cryptoHmacOne(hashTypeSha256, regionKey, S3_BUF);
|
||||
const Buffer *const regionKey = cryptoHmacOne(hashTypeSha256, dateKey, BUFSTR(this->region));
|
||||
const Buffer *const serviceKey = cryptoHmacOne(hashTypeSha256, regionKey, S3_BUF);
|
||||
|
||||
// Switch to the object context so signing key and date are not lost
|
||||
MEM_CONTEXT_OBJ_BEGIN(this)
|
||||
@ -233,7 +233,7 @@ storageS3Auth(
|
||||
}
|
||||
|
||||
// Generate authorization header
|
||||
const String *authorization = strNewFmt(
|
||||
const String *const authorization = strNewFmt(
|
||||
AWS4_HMAC_SHA256 " Credential=%s/%s/%s/" S3 "/" AWS4_REQUEST ",SignedHeaders=%s,Signature=%s",
|
||||
strZ(this->accessKey), strZ(date), strZ(this->region), strZ(signedHeaders),
|
||||
strZ(strNewEncode(encodingHex, cryptoHmacOne(hashTypeSha256, this->signingKey, BUFSTR(stringToSign)))));
|
||||
@ -313,9 +313,9 @@ storageS3AuthAuto(StorageS3 *const this, HttpHeader *const header)
|
||||
if (this->credRole == NULL)
|
||||
{
|
||||
// Request the role
|
||||
HttpRequest *request = httpRequestNewP(
|
||||
HttpRequest *const request = httpRequestNewP(
|
||||
this->credHttpClient, HTTP_VERB_GET_STR, STRDEF(S3_CREDENTIAL_PATH), .header = header);
|
||||
HttpResponse *response = httpRequestResponse(request, true);
|
||||
HttpResponse *const response = httpRequestResponse(request, true);
|
||||
|
||||
// Not found likely means no role is associated with this instance
|
||||
if (httpResponseCode(response) == HTTP_RESPONSE_CODE_NOT_FOUND)
|
||||
@ -356,12 +356,12 @@ storageS3AuthAuto(StorageS3 *const this, HttpHeader *const header)
|
||||
httpRequestError(request, response);
|
||||
|
||||
// Get credentials from the JSON response
|
||||
KeyValue *credential = varKv(jsonToVar(strNewBuf(httpResponseContent(response))));
|
||||
const KeyValue *const credential = varKv(jsonToVar(strNewBuf(httpResponseContent(response))));
|
||||
|
||||
MEM_CONTEXT_OBJ_BEGIN(this)
|
||||
{
|
||||
// Check the code field for errors
|
||||
const Variant *code = kvGetDefault(credential, S3_JSON_TAG_CODE_VAR, VARSTRDEF("code field is missing"));
|
||||
const Variant *const code = kvGetDefault(credential, S3_JSON_TAG_CODE_VAR, VARSTRDEF("code field is missing"));
|
||||
CHECK(FormatError, code != NULL, "error code missing");
|
||||
|
||||
if (!varEq(code, S3_JSON_VALUE_SUCCESS_VAR))
|
||||
@ -451,7 +451,7 @@ storageS3AuthWebId(StorageS3 *const this, const HttpHeader *const header)
|
||||
Process S3 request
|
||||
***********************************************************************************************************************************/
|
||||
FN_EXTERN HttpRequest *
|
||||
storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, StorageS3RequestAsyncParam param)
|
||||
storageS3RequestAsync(StorageS3 *const this, const String *const verb, const String *path, const StorageS3RequestAsyncParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_S3, this);
|
||||
@ -473,7 +473,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, S
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
HttpHeader *requestHeader =
|
||||
HttpHeader *const requestHeader =
|
||||
param.header == NULL ? httpHeaderNew(this->headerRedactList) : httpHeaderDup(param.header, this->headerRedactList);
|
||||
|
||||
// Set content length
|
||||
@ -572,7 +572,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, S
|
||||
}
|
||||
|
||||
FN_EXTERN HttpResponse *
|
||||
storageS3Response(HttpRequest *request, StorageS3ResponseParam param)
|
||||
storageS3Response(HttpRequest *const request, const StorageS3ResponseParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(HTTP_REQUEST, request);
|
||||
@ -602,7 +602,7 @@ storageS3Response(HttpRequest *request, StorageS3ResponseParam param)
|
||||
}
|
||||
|
||||
FN_EXTERN HttpResponse *
|
||||
storageS3Request(StorageS3 *this, const String *verb, const String *path, StorageS3RequestParam param)
|
||||
storageS3Request(StorageS3 *const this, const String *const verb, const String *const path, const StorageS3RequestParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_S3, this);
|
||||
@ -634,8 +634,8 @@ General function for listing files to be used by other list routines
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageS3ListInternal(
|
||||
StorageS3 *this, const String *path, StorageInfoLevel level, const String *expression, bool recurse,
|
||||
StorageListCallback callback, void *callbackData)
|
||||
StorageS3 *const this, const String *const path, const StorageInfoLevel level, const String *const expression,
|
||||
const bool recurse, StorageListCallback callback, void *const callbackData)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_S3, this);
|
||||
@ -655,15 +655,10 @@ storageS3ListInternal(
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Build the base prefix by stripping off the initial /
|
||||
const String *basePrefix;
|
||||
|
||||
if (strSize(path) == 1)
|
||||
basePrefix = EMPTY_STR;
|
||||
else
|
||||
basePrefix = strNewFmt("%s/", strZ(strSub(path, 1)));
|
||||
const String *const basePrefix = strSize(path) == 1 ? EMPTY_STR : strNewFmt("%s/", strZ(strSub(path, 1)));
|
||||
|
||||
// Get the expression prefix when possible to limit initial results
|
||||
const String *expressionPrefix = regExpPrefix(expression);
|
||||
const String *const expressionPrefix = regExpPrefix(expression);
|
||||
|
||||
// If there is an expression prefix then use it to build the query prefix, otherwise query prefix is base prefix
|
||||
const String *queryPrefix;
|
||||
@ -679,7 +674,7 @@ storageS3ListInternal(
|
||||
}
|
||||
|
||||
// Create query
|
||||
HttpQuery *query = httpQueryNewP();
|
||||
HttpQuery *const query = httpQueryNewP();
|
||||
|
||||
// Add the delimiter to not recurse
|
||||
if (!recurse)
|
||||
@ -715,7 +710,7 @@ storageS3ListInternal(
|
||||
else
|
||||
response = storageS3RequestP(this, HTTP_VERB_GET_STR, FSLASH_STR, .query = query);
|
||||
|
||||
XmlNode *xmlRoot = xmlDocumentRoot(xmlDocumentNewBuf(httpResponseContent(response)));
|
||||
const XmlNode *const xmlRoot = xmlDocumentRoot(xmlDocumentNewBuf(httpResponseContent(response)));
|
||||
|
||||
// If list is truncated then send an async request to get more data
|
||||
if (strEq(xmlNodeContent(xmlNodeChild(xmlRoot, S3_XML_TAG_IS_TRUNCATED_STR, true)), TRUE_STR))
|
||||
@ -735,11 +730,11 @@ storageS3ListInternal(
|
||||
}
|
||||
|
||||
// Get prefix list
|
||||
XmlNodeList *subPathList = xmlNodeChildList(xmlRoot, S3_XML_TAG_COMMON_PREFIXES_STR);
|
||||
const XmlNodeList *const subPathList = xmlNodeChildList(xmlRoot, S3_XML_TAG_COMMON_PREFIXES_STR);
|
||||
|
||||
for (unsigned int subPathIdx = 0; subPathIdx < xmlNodeLstSize(subPathList); subPathIdx++)
|
||||
{
|
||||
const XmlNode *subPathNode = xmlNodeLstGet(subPathList, subPathIdx);
|
||||
const XmlNode *const subPathNode = xmlNodeLstGet(subPathList, subPathIdx);
|
||||
|
||||
// Get path name
|
||||
StorageInfo info =
|
||||
@ -761,11 +756,11 @@ storageS3ListInternal(
|
||||
}
|
||||
|
||||
// Get file list
|
||||
XmlNodeList *fileList = xmlNodeChildList(xmlRoot, S3_XML_TAG_CONTENTS_STR);
|
||||
const XmlNodeList *const fileList = xmlNodeChildList(xmlRoot, S3_XML_TAG_CONTENTS_STR);
|
||||
|
||||
for (unsigned int fileIdx = 0; fileIdx < xmlNodeLstSize(fileList); fileIdx++)
|
||||
{
|
||||
const XmlNode *fileNode = xmlNodeLstGet(fileList, fileIdx);
|
||||
const XmlNode *const fileNode = xmlNodeLstGet(fileList, fileIdx);
|
||||
|
||||
// Get file name
|
||||
StorageInfo info =
|
||||
@ -882,7 +877,7 @@ storageS3List(THIS_VOID, const String *const path, const StorageInfoLevel level,
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageRead *
|
||||
storageS3NewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageInterfaceNewReadParam param)
|
||||
storageS3NewRead(THIS_VOID, const String *const file, const bool ignoreMissing, const StorageInterfaceNewReadParam param)
|
||||
{
|
||||
THIS(StorageS3);
|
||||
|
||||
@ -902,7 +897,7 @@ storageS3NewRead(THIS_VOID, const String *file, bool ignoreMissing, StorageInter
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
static StorageWrite *
|
||||
storageS3NewWrite(THIS_VOID, const String *file, StorageInterfaceNewWriteParam param)
|
||||
storageS3NewWrite(THIS_VOID, const String *const file, const StorageInterfaceNewWriteParam param)
|
||||
{
|
||||
THIS(StorageS3);
|
||||
|
||||
@ -955,7 +950,8 @@ storageS3PathRemoveInternal(StorageS3 *const this, HttpRequest *const request, X
|
||||
// Nothing is returned when there are no errors
|
||||
if (!bufEmpty(response))
|
||||
{
|
||||
XmlNodeList *errorList = xmlNodeChildList(xmlDocumentRoot(xmlDocumentNewBuf(response)), S3_XML_TAG_ERROR_STR);
|
||||
const XmlNodeList *const errorList = xmlNodeChildList(
|
||||
xmlDocumentRoot(xmlDocumentNewBuf(response)), S3_XML_TAG_ERROR_STR);
|
||||
|
||||
// Attempt to remove errored files one at a time rather than retrying the batch
|
||||
for (unsigned int errorIdx = 0; errorIdx < xmlNodeLstSize(errorList); errorIdx++)
|
||||
@ -991,7 +987,7 @@ storageS3PathRemoveInternal(StorageS3 *const this, HttpRequest *const request, X
|
||||
}
|
||||
|
||||
static void
|
||||
storageS3PathRemoveCallback(void *callbackData, const StorageInfo *info)
|
||||
storageS3PathRemoveCallback(void *const callbackData, const StorageInfo *const info)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM_P(VOID, callbackData);
|
||||
@ -1004,7 +1000,7 @@ storageS3PathRemoveCallback(void *callbackData, const StorageInfo *info)
|
||||
// Only delete files since paths don't really exist
|
||||
if (info->type == storageTypeFile)
|
||||
{
|
||||
StorageS3PathRemoveData *data = (StorageS3PathRemoveData *)callbackData;
|
||||
StorageS3PathRemoveData *const data = (StorageS3PathRemoveData *)callbackData;
|
||||
|
||||
// If there is something to delete then create the request
|
||||
if (data->xml == NULL)
|
||||
@ -1047,7 +1043,7 @@ storageS3PathRemoveCallback(void *callbackData, const StorageInfo *info)
|
||||
}
|
||||
|
||||
static bool
|
||||
storageS3PathRemove(THIS_VOID, const String *path, bool recurse, StorageInterfacePathRemoveParam param)
|
||||
storageS3PathRemove(THIS_VOID, const String *const path, const bool recurse, const StorageInterfacePathRemoveParam param)
|
||||
{
|
||||
THIS(StorageS3);
|
||||
|
||||
|
@ -103,7 +103,7 @@ storageWriteS3Part(StorageWriteS3 *const this)
|
||||
}
|
||||
|
||||
static void
|
||||
storageWriteS3PartAsync(StorageWriteS3 *this)
|
||||
storageWriteS3PartAsync(StorageWriteS3 *const this)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(STORAGE_WRITE_S3, this);
|
||||
@ -122,7 +122,7 @@ storageWriteS3PartAsync(StorageWriteS3 *this)
|
||||
if (this->uploadId == NULL)
|
||||
{
|
||||
// Initiate mult-part upload
|
||||
XmlNode *xmlRoot = xmlDocumentRoot(
|
||||
const XmlNode *const xmlRoot = xmlDocumentRoot(
|
||||
xmlDocumentNewBuf(
|
||||
httpResponseContent(
|
||||
storageS3RequestP(
|
||||
@ -140,7 +140,7 @@ storageWriteS3PartAsync(StorageWriteS3 *this)
|
||||
}
|
||||
|
||||
// Upload the part async
|
||||
HttpQuery *query = httpQueryNewP();
|
||||
HttpQuery *const query = httpQueryNewP();
|
||||
httpQueryAdd(query, S3_QUERY_UPLOAD_ID_STR, this->uploadId);
|
||||
httpQueryAdd(query, S3_QUERY_PART_NUMBER_STR, strNewFmt("%u", strLstSize(this->uploadPartList) + 1));
|
||||
|
||||
@ -160,7 +160,7 @@ storageWriteS3PartAsync(StorageWriteS3 *this)
|
||||
Write to internal buffer
|
||||
***********************************************************************************************************************************/
|
||||
static void
|
||||
storageWriteS3(THIS_VOID, const Buffer *buffer)
|
||||
storageWriteS3(THIS_VOID, const Buffer *const buffer)
|
||||
{
|
||||
THIS(StorageWriteS3);
|
||||
|
||||
@ -228,21 +228,21 @@ storageWriteS3Close(THIS_VOID)
|
||||
storageWriteS3Part(this);
|
||||
|
||||
// Generate the xml part list
|
||||
XmlDocument *partList = xmlDocumentNew(S3_XML_TAG_COMPLETE_MULTIPART_UPLOAD_STR);
|
||||
XmlDocument *const partList = xmlDocumentNew(S3_XML_TAG_COMPLETE_MULTIPART_UPLOAD_STR);
|
||||
|
||||
for (unsigned int partIdx = 0; partIdx < strLstSize(this->uploadPartList); partIdx++)
|
||||
{
|
||||
XmlNode *partNode = xmlNodeAdd(xmlDocumentRoot(partList), S3_XML_TAG_PART_STR);
|
||||
XmlNode *const partNode = xmlNodeAdd(xmlDocumentRoot(partList), S3_XML_TAG_PART_STR);
|
||||
xmlNodeContentSet(xmlNodeAdd(partNode, S3_XML_TAG_PART_NUMBER_STR), strNewFmt("%u", partIdx + 1));
|
||||
xmlNodeContentSet(xmlNodeAdd(partNode, S3_XML_TAG_ETAG_STR), strLstGet(this->uploadPartList, partIdx));
|
||||
}
|
||||
|
||||
// Finalize the multi-part upload
|
||||
HttpRequest *request = storageS3RequestAsyncP(
|
||||
HttpRequest *const request = storageS3RequestAsyncP(
|
||||
this->storage, HTTP_VERB_POST_STR, this->interface.name,
|
||||
.query = httpQueryAdd(httpQueryNewP(), S3_QUERY_UPLOAD_ID_STR, this->uploadId),
|
||||
.content = xmlDocumentBuf(partList));
|
||||
HttpResponse *response = storageS3ResponseP(request);
|
||||
HttpResponse *const response = storageS3ResponseP(request);
|
||||
|
||||
// Error when no etag in the result. This indicates that the request did not succeed despite the success code.
|
||||
if (xmlNodeChild(
|
||||
|
@ -60,7 +60,7 @@ storageReadSftpOpen(THIS_VOID)
|
||||
|
||||
if (this->sftpHandle == NULL)
|
||||
{
|
||||
int rc = libssh2_session_last_errno(this->session);
|
||||
const int rc = libssh2_session_last_errno(this->session);
|
||||
|
||||
if (rc == LIBSSH2_ERROR_SFTP_PROTOCOL || rc == LIBSSH2_ERROR_EAGAIN)
|
||||
{
|
||||
|
@ -165,8 +165,6 @@ storageSftpUpdateKnownHostsFile(
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
int rc;
|
||||
|
||||
// Init a known host collection for the user's known_hosts file
|
||||
const char *const userKnownHostsFile = strZ(strNewFmt("%s%s", strZ(userHome()), "/.ssh/known_hosts"));
|
||||
LIBSSH2_KNOWNHOSTS *const userKnownHostsList = libssh2_knownhost_init(this->session);
|
||||
@ -185,6 +183,8 @@ storageSftpUpdateKnownHostsFile(
|
||||
{
|
||||
// Read the user's known_hosts file entries into the collection. libssh2_knownhost_readfile() returns the number of
|
||||
// successfully loaded hosts or a negative value on error, an empty known hosts file will return 0.
|
||||
int rc;
|
||||
|
||||
if ((rc = libssh2_knownhost_readfile(userKnownHostsList, userKnownHostsFile, LIBSSH2_KNOWNHOST_FILE_OPENSSH)) < 0)
|
||||
{
|
||||
// Missing known_hosts file will return LIBSSH2_ERROR_FILE. Possibly issues other than missing may return this.
|
||||
@ -898,7 +898,7 @@ storageSftpPathCreate(
|
||||
|
||||
if (rc == LIBSSH2_ERROR_SFTP_PROTOCOL)
|
||||
{
|
||||
uint64_t sftpErrno = libssh2_sftp_last_error(this->sftpSession);
|
||||
const uint64_t sftpErrno = libssh2_sftp_last_error(this->sftpSession);
|
||||
|
||||
// libssh2 may return LIBSSH2_FX_FAILURE if the directory already exists
|
||||
if (sftpErrno == LIBSSH2_FX_FAILURE)
|
||||
@ -974,7 +974,7 @@ storageSftpPathRemove(THIS_VOID, const String *const path, const bool recurse, c
|
||||
// Recurse if requested
|
||||
if (recurse)
|
||||
{
|
||||
StorageList *const list = storageInterfaceListP(this, path, storageInfoLevelExists);
|
||||
const StorageList *const list = storageInterfaceListP(this, path, storageInfoLevelExists);
|
||||
|
||||
if (list != NULL)
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ storageNew(
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN bool
|
||||
storageCopy(StorageRead *source, StorageWrite *destination)
|
||||
storageCopy(StorageRead *const source, StorageWrite *const destination)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_READ, source);
|
||||
@ -141,7 +141,7 @@ storageCopy(StorageRead *source, StorageWrite *destination)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN bool
|
||||
storageExists(const Storage *this, const String *pathExp, StorageExistsParam param)
|
||||
storageExists(const Storage *const this, const String *const pathExp, const StorageExistsParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -155,14 +155,14 @@ storageExists(const Storage *this, const String *pathExp, StorageExistsParam par
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
Wait *wait = waitNew(param.timeout);
|
||||
Wait *const wait = waitNew(param.timeout);
|
||||
|
||||
// Loop until file exists or timeout
|
||||
do
|
||||
{
|
||||
// storageInfoLevelBasic is required here because storageInfoLevelExists will not return the type and this function
|
||||
// specifically wants to test existence of a *file*, not just the existence of anything with the specified name.
|
||||
StorageInfo info = storageInfoP(
|
||||
const StorageInfo info = storageInfoP(
|
||||
this, pathExp, .level = storageInfoLevelBasic, .ignoreMissing = true, .followLink = true);
|
||||
|
||||
// Only exists if it is a file
|
||||
@ -177,7 +177,7 @@ storageExists(const Storage *this, const String *pathExp, StorageExistsParam par
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN Buffer *
|
||||
storageGet(StorageRead *file, StorageGetParam param)
|
||||
storageGet(StorageRead *const file, const StorageGetParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_READ, file);
|
||||
@ -207,7 +207,7 @@ storageGet(StorageRead *file, StorageGetParam param)
|
||||
else
|
||||
{
|
||||
result = bufNew(0);
|
||||
Buffer *read = bufNew(ioBufferSize());
|
||||
Buffer *const read = bufNew(ioBufferSize());
|
||||
|
||||
do
|
||||
{
|
||||
@ -234,7 +234,7 @@ storageGet(StorageRead *file, StorageGetParam param)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN StorageInfo
|
||||
storageInfo(const Storage *this, const String *fileExp, StorageInfoParam param)
|
||||
storageInfo(const Storage *const this, const String *const fileExp, StorageInfoParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -255,7 +255,7 @@ storageInfo(const Storage *this, const String *fileExp, StorageInfoParam param)
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Build the path
|
||||
String *file = storagePathP(this, fileExp, .noEnforce = param.noPathEnforce);
|
||||
const String *const file = storagePathP(this, fileExp, .noEnforce = param.noPathEnforce);
|
||||
|
||||
// Call driver function
|
||||
if (param.level == storageInfoLevelDefault)
|
||||
@ -360,7 +360,7 @@ storageLinkCreate(
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN StringList *
|
||||
storageList(const Storage *this, const String *pathExp, StorageListParam param)
|
||||
storageList(const Storage *const this, const String *const pathExp, const StorageListParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -398,7 +398,7 @@ storageList(const Storage *this, const String *pathExp, StorageListParam param)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
storageMove(const Storage *this, StorageRead *source, StorageWrite *destination)
|
||||
storageMove(const Storage *const this, StorageRead *const source, StorageWrite *const destination)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_READ, source);
|
||||
@ -438,7 +438,7 @@ storageMove(const Storage *this, StorageRead *source, StorageWrite *destination)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN StorageRead *
|
||||
storageNewRead(const Storage *this, const String *fileExp, StorageNewReadParam param)
|
||||
storageNewRead(const Storage *const this, const String *const fileExp, const StorageNewReadParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -452,7 +452,7 @@ storageNewRead(const Storage *this, const String *fileExp, StorageNewReadParam p
|
||||
ASSERT(this != NULL);
|
||||
ASSERT(param.limit == NULL || varType(param.limit) == varTypeUInt64);
|
||||
|
||||
StorageRead *result = NULL;
|
||||
StorageRead *result;
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
@ -469,7 +469,7 @@ storageNewRead(const Storage *this, const String *fileExp, StorageNewReadParam p
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN StorageWrite *
|
||||
storageNewWrite(const Storage *this, const String *fileExp, StorageNewWriteParam param)
|
||||
storageNewWrite(const Storage *const this, const String *const fileExp, const StorageNewWriteParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -492,7 +492,7 @@ storageNewWrite(const Storage *this, const String *fileExp, StorageNewWriteParam
|
||||
// noTruncate does not work with atomic writes because a new file is always created for atomic writes
|
||||
ASSERT(!param.noTruncate || param.noAtomic);
|
||||
|
||||
StorageWrite *result = NULL;
|
||||
StorageWrite *result;
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
@ -512,7 +512,7 @@ storageNewWrite(const Storage *this, const String *fileExp, StorageNewWriteParam
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN String *
|
||||
storagePath(const Storage *this, const String *pathExp, StoragePathParam param)
|
||||
storagePath(const Storage *const this, const String *pathExp, const StoragePathParam param)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STORAGE, this);
|
||||
@ -522,7 +522,7 @@ storagePath(const Storage *this, const String *pathExp, StoragePathParam param)
|
||||
|
||||
ASSERT(this != NULL);
|
||||
|
||||
String *result = NULL;
|
||||
String *result;
|
||||
|
||||
// If there is no path expression then return the base storage path
|
||||
if (pathExp == NULL)
|
||||
@ -560,14 +560,14 @@ storagePath(const Storage *this, const String *pathExp, StoragePathParam param)
|
||||
THROW_FMT(AssertError, "expression '%s' not valid without callback function", strZ(pathExp));
|
||||
|
||||
// Get position of the expression end
|
||||
char *end = strchr(strZ(pathExp), '>');
|
||||
const char *const end = strchr(strZ(pathExp), '>');
|
||||
|
||||
// Error if end is not found
|
||||
if (end == NULL)
|
||||
THROW_FMT(AssertError, "end > not found in path expression '%s'", strZ(pathExp));
|
||||
|
||||
// Create a string from the expression
|
||||
String *expression = strNewZN(strZ(pathExp), (size_t)(end - strZ(pathExp) + 1));
|
||||
String *const expression = strNewZN(strZ(pathExp), (size_t)(end - strZ(pathExp) + 1));
|
||||
|
||||
// Create a string from the path if there is anything left after the expression
|
||||
String *path = NULL;
|
||||
@ -614,7 +614,7 @@ storagePath(const Storage *this, const String *pathExp, StoragePathParam param)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
storagePathCreate(const Storage *this, const String *pathExp, StoragePathCreateParam param)
|
||||
storagePathCreate(const Storage *const this, const String *const pathExp, const StoragePathCreateParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -630,12 +630,10 @@ storagePathCreate(const Storage *this, const String *pathExp, StoragePathCreateP
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Build the path
|
||||
String *path = storagePathP(this, pathExp);
|
||||
|
||||
// Call driver function
|
||||
storageInterfacePathCreateP(
|
||||
storageDriver(this), path, param.errorOnExists, param.noParentCreate, param.mode != 0 ? param.mode : this->modePath);
|
||||
storageDriver(this), storagePathP(this, pathExp), param.errorOnExists, param.noParentCreate,
|
||||
param.mode != 0 ? param.mode : this->modePath);
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
@ -644,7 +642,7 @@ storagePathCreate(const Storage *this, const String *pathExp, StoragePathCreateP
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN bool
|
||||
storagePathExists(const Storage *this, const String *pathExp)
|
||||
storagePathExists(const Storage *const this, const String *const pathExp)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -656,14 +654,14 @@ storagePathExists(const Storage *this, const String *pathExp)
|
||||
|
||||
// storageInfoLevelBasic is required here because storageInfoLevelExists will not return the type and this function specifically
|
||||
// wants to test existence of a *path*, not just the existence of anything with the specified name.
|
||||
StorageInfo info = storageInfoP(this, pathExp, .level = storageInfoLevelBasic, .ignoreMissing = true, .followLink = true);
|
||||
const StorageInfo info = storageInfoP(this, pathExp, .level = storageInfoLevelBasic, .ignoreMissing = true, .followLink = true);
|
||||
|
||||
FUNCTION_LOG_RETURN(BOOL, info.exists && info.type == storageTypePath);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
storagePathRemove(const Storage *this, const String *pathExp, StoragePathRemoveParam param)
|
||||
storagePathRemove(const Storage *const this, const String *const pathExp, const StoragePathRemoveParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -680,13 +678,11 @@ storagePathRemove(const Storage *this, const String *pathExp, StoragePathRemoveP
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Build the path
|
||||
String *path = storagePathP(this, pathExp);
|
||||
const String *const path = storagePathP(this, pathExp);
|
||||
|
||||
// Call driver function
|
||||
if (!storageInterfacePathRemoveP(storageDriver(this), path, param.recurse) && param.errorOnMissing)
|
||||
{
|
||||
THROW_FMT(PathRemoveError, STORAGE_ERROR_PATH_REMOVE_MISSING, strZ(path));
|
||||
}
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
@ -695,7 +691,7 @@ storagePathRemove(const Storage *this, const String *pathExp, StoragePathRemoveP
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
storagePathSync(const Storage *this, const String *pathExp)
|
||||
storagePathSync(const Storage *const this, const String *const pathExp)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -720,7 +716,7 @@ storagePathSync(const Storage *this, const String *pathExp)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
storagePut(StorageWrite *file, const Buffer *buffer)
|
||||
storagePut(StorageWrite *const file, const Buffer *const buffer)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE_WRITE, file);
|
||||
@ -738,7 +734,7 @@ storagePut(StorageWrite *file, const Buffer *buffer)
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN void
|
||||
storageRemove(const Storage *this, const String *fileExp, StorageRemoveParam param)
|
||||
storageRemove(const Storage *const this, const String *const fileExp, const StorageRemoveParam param)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(STORAGE, this);
|
||||
@ -751,11 +747,8 @@ storageRemove(const Storage *this, const String *fileExp, StorageRemoveParam par
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Build the path
|
||||
String *file = storagePathP(this, fileExp);
|
||||
|
||||
// Call driver function
|
||||
storageInterfaceRemoveP(storageDriver(this), file, .errorOnMissing = param.errorOnMissing);
|
||||
storageInterfaceRemoveP(storageDriver(this), storagePathP(this, fileExp), .errorOnMissing = param.errorOnMissing);
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user