diff mbox series

[2/4] xfs_restore: check return value

Message ID 155085405082.5141.12150949924461780415.stgit@magnolia (mailing list archive)
State Superseded
Headers show
Series xfsdump: update to use fallocate | expand

Commit Message

Darrick J. Wong Feb. 22, 2019, 4:47 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Check the return value of the unlink call when creating a new file.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 restore/dirattr.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Allison Henderson May 7, 2019, 12:11 a.m. UTC | #1
Looks ok.
Reviewed-by: Allison Collins <allison.henderson@oracle.com>

On 2/22/19 9:47 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Check the return value of the unlink call when creating a new file.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>   restore/dirattr.c |    4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> 
> diff --git a/restore/dirattr.c b/restore/dirattr.c
> index 0fb2877..4257a1b 100644
> --- a/restore/dirattr.c
> +++ b/restore/dirattr.c
> @@ -67,7 +67,9 @@ create_filled_file(
>   	int		fd;
>   	int		ret;
>   
> -	(void)unlink(pathname);
> +	ret = unlink(pathname);
> +	if (ret && errno != ENOENT)
> +		return ret;
>   
>   	fd = open(pathname, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
>   	if (fd < 0)
>
diff mbox series

Patch

diff --git a/restore/dirattr.c b/restore/dirattr.c
index 0fb2877..4257a1b 100644
--- a/restore/dirattr.c
+++ b/restore/dirattr.c
@@ -67,7 +67,9 @@  create_filled_file(
 	int		fd;
 	int		ret;
 
-	(void)unlink(pathname);
+	ret = unlink(pathname);
+	if (ret && errno != ENOENT)
+		return ret;
 
 	fd = open(pathname, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
 	if (fd < 0)