[sheepdog] [PATCH] sheep/md: temp file cannot be removed

Liu Yuan namei.unix at gmail.com
Wed Jul 2 11:37:11 CEST 2014


On Wed, Jul 02, 2014 at 04:59:27PM +0800, Ruoyu wrote:
> d_name is only the file's name without absolute path. To unlink it
> successfully, we must give the full name.
> 
> Signed-off-by: Ruoyu <liangry at ucweb.com>
> ---
>  sheep/md.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/sheep/md.c b/sheep/md.c
> index 538f696..f6d3b8e 100644
> --- a/sheep/md.c
> +++ b/sheep/md.c
> @@ -185,6 +185,7 @@ static int for_each_object_in_path(const char *path,
>  	struct dirent *d;
>  	uint64_t oid;
>  	int ret = SD_RES_SUCCESS;
> +	char file_name[PATH_MAX];
>  
>  	dir = opendir(path);
>  	if (unlikely(!dir)) {
> @@ -208,8 +209,12 @@ static int for_each_object_in_path(const char *path,
>  		/* don't call callback against temporary objects */
>  		if (is_tmp_dentry(d->d_name)) {
>  			if (cleanup) {
> -				sd_debug("remove tmp object %s", d->d_name);
> -				unlink(d->d_name);
> +				snprintf(file_name, sizeof(file_name),
> +						"%s/%s", path, d->d_name);
> +				sd_debug("remove tmp object %s", file_name);
> +				if (unlink(file_name) < 0)
> +					sd_err("failed to unlink %s: %m",
> +							file_name);
>  			}
>  			continue;
>  		}
> -- 
> 1.8.3.2
> 
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog

Applied thanks

Yuan



More information about the sheepdog mailing list