1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-04-13 11:30:40 +02:00

Add special file type to storageInfo().

There's not much we can do with special files, but higher level logic can at least exclude them gracefully rather than throwing a hard error.
This commit is contained in:
David Steele 2019-08-23 07:24:25 -04:00
parent 04e4fde573
commit 2862f480cd
5 changed files with 21 additions and 3 deletions

View File

@ -62,6 +62,12 @@ storageManifestXsInfo(const String *path, const StorageInfo *info)
strCatFmt(json, "d\",\"mode\":\"%04o\"}", info->mode);
break;
}
case storageTypeSpecial:
{
strCatFmt(json, "s\",\"mode\":\"%04o\"}", info->mode);
break;
}
}
return json;

View File

@ -14,6 +14,7 @@ typedef enum
storageTypeFile,
storageTypePath,
storageTypeLink,
storageTypeSpecial,
} StorageType;
/***********************************************************************************************************************************

View File

@ -143,7 +143,7 @@ storagePosixInfo(THIS_VOID, const String *file, bool followLink)
result.linkDestination = strNewN(linkDestination, (size_t)linkDestinationSize);
}
else
THROW_FMT(FileInfoError, "invalid type for '%s'", strPtr(file));
result.type = storageTypeSpecial;
result.mode = statFile.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
}

View File

@ -198,6 +198,8 @@ sub run
utime(1111111113, 1111111113, $self->testPath() . '/sub1/sub2/test-sub2.txt');
executeTest('chmod 0646 ' . $self->testPath() . '/sub1/test-sub1.txt');
executeTest('mkfifo -m 606 ' . $self->testPath() . '/sub1/apipe');
executeTest('ln ' . $self->testPath() . '/test.txt ' . $self->testPath() . '/sub1/test-hardlink.txt');
executeTest('ln ' . $self->testPath() . '/test.txt ' . $self->testPath() . '/sub1/sub2/test-hardlink.txt');
@ -212,6 +214,7 @@ sub run
sub {$self->storageLocal()->manifest($self->testPath())},
'{. => {group => ' . $self->group() . ', mode => 0770, type => d, user => ' . $self->pgUser() . '}, ' .
'sub1 => {group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}, ' .
'sub1/apipe => {group => ' . $self->group() . ', mode => 0606, type => s, user => ' . $self->pgUser() . '}, ' .
'sub1/sub2 => {group => ' . $self->group() . ', mode => 0750, type => d, user => ' . $self->pgUser() . '}, ' .
'sub1/sub2/test => {group => ' . $self->group() . ', link_destination => ../.., type => l, user => ' .
$self->pgUser() . '}, ' .

View File

@ -243,9 +243,17 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
String *pipeName = strNewFmt("%s/testpipe", testPath());
TEST_RESULT_INT(system(strPtr(strNewFmt("mkfifo %s", strPtr(pipeName)))), 0, "create pipe");
TEST_RESULT_INT(system(strPtr(strNewFmt("mkfifo -m 666 %s", strPtr(pipeName)))), 0, "create pipe");
TEST_ERROR_FMT(storageInfoNP(storageTest, pipeName), FileInfoError, "invalid type for '%s'", strPtr(pipeName));
TEST_ASSIGN(info, storageInfoNP(storageTest, pipeName), "get info from pipe (special file)");
TEST_RESULT_PTR(info.name, NULL, " name is not set");
TEST_RESULT_BOOL(info.exists, true, " check exists");
TEST_RESULT_INT(info.type, storageTypeSpecial, " check type");
TEST_RESULT_INT(info.size, 0, " check size");
TEST_RESULT_INT(info.mode, 0666, " check mode");
TEST_RESULT_STR(strPtr(info.linkDestination), NULL, " check link destination");
TEST_RESULT_STR(strPtr(info.user), testUser(), " check user");
TEST_RESULT_STR(strPtr(info.group), testGroup(), " check group");
storageRemoveP(storageTest, pipeName, .errorOnMissing = true);
}