Skip to content

Commit

Permalink
[#149] Use return value from functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Oct 22, 2023
1 parent 0056d16 commit f61dbe0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/libpgmoneta/archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ write_tar_file(struct archive* a, char* current_real_path, char* current_save_pa
{
char real_path[MAX_PATH];
char save_path[MAX_PATH];
ssize_t size;
struct archive_entry* entry;
struct stat s;
struct dirent* dent;
Expand Down Expand Up @@ -376,7 +377,11 @@ write_tar_file(struct archive* a, char* current_real_path, char* current_save_pa
{
char target[MAX_PATH];
memset(target, 0, sizeof(target));
readlink(real_path, target, sizeof(target));
size = readlink(real_path, target, sizeof(target));
if (size == -1)
{
return;
}

archive_entry_set_filetype(entry, AE_IFLNK);
archive_entry_set_perm(entry, s.st_mode);
Expand Down
4 changes: 2 additions & 2 deletions src/libpgmoneta/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pgmoneta_parse_manifest(char* manifest_path, struct manifest** manifest)
goto error;
}

fread(json, 1, size, f);
size = fread(json, 1, size, f);

manifest_json = cJSON_Parse(json);
if (manifest_json == NULL)
Expand Down Expand Up @@ -338,4 +338,4 @@ manifest_file_hash(char* algorithm, char* file_path, char** hash)
stat = 1;
}
return stat;
}
}
15 changes: 13 additions & 2 deletions src/libpgmoneta/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,7 @@ copy_tablespaces(char* from, char* to, char* base, char* server, char* id, struc
char* to_tblspc = NULL;
int idx = -1;
DIR* d = NULL;
ssize_t size;
struct dirent* entry;

from_tblspc = pgmoneta_append(from_tblspc, from);
Expand Down Expand Up @@ -1540,7 +1541,11 @@ copy_tablespaces(char* from, char* to, char* base, char* server, char* id, struc
link = pgmoneta_append(link, entry->d_name);

memset(&path[0], 0, sizeof(path));
readlink(link, &path[0], sizeof(path));
size = readlink(link, &path[0], sizeof(path));
if (size == -1)
{
goto error;
}

if (pgmoneta_ends_with(&path[0], "/"))
{
Expand Down Expand Up @@ -1958,6 +1963,7 @@ pgmoneta_symlink_at_file(char* from, char* to)
int dirfd;
int ret;
char* dir_path;
char* ret_path;
char absolute_path[MAX_PATH];

dir_path = dirname(strdup(from));
Expand All @@ -1972,7 +1978,12 @@ pgmoneta_symlink_at_file(char* from, char* to)
if (!pgmoneta_starts_with(from, "/"))
{
memset(absolute_path, 0, sizeof(absolute_path));
realpath(from, absolute_path);
ret_path = realpath(from, absolute_path);
if (ret_path == NULL)
{
return 1;
}

ret = symlinkat(to, dirfd, absolute_path);
}
else
Expand Down

0 comments on commit f61dbe0

Please sign in to comment.