git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Teach fsck and prune that tmp_obj_ file names may not be 14 bytes long
@ 2008-08-05 18:01 Brandon Casey
  2008-08-05 19:07 ` Shawn O. Pearce
  0 siblings, 1 reply; 2+ messages in thread
From: Brandon Casey @ 2008-08-05 18:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, Shawn O. Pearce

As Shawn pointed out, not all temporary file creation routines can
ensure that the generated temporary file is of a certain length.
e.g. Java's createTempFile(prefix, suffix). So just depend on the
prefix 'tmp_obj_' for detection.

Update prune, and fix the "fix" introduced by a08c53a1 :)

Signed-off-by: Brandon "appendixless" Casey <casey@nrlssc.navy.mil>
---
 builtin-fsck.c  |    2 +-
 builtin-prune.c |    9 ++++-----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/builtin-fsck.c b/builtin-fsck.c
index 6eb7da8..d3f3de9 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -385,7 +385,7 @@ static void fsck_dir(int i, char *path)
 			add_sha1_list(sha1, DIRENT_SORT_HINT(de));
 			continue;
 		}
-		if (prefixcmp(de->d_name, "tmp_obj_"))
+		if (!prefixcmp(de->d_name, "tmp_obj_"))
 			continue;
 		fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
 	}
diff --git a/builtin-prune.c b/builtin-prune.c
index 947de8c..c767a0a 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -69,11 +69,6 @@ static int prune_dir(int i, char *path)
 			if (de->d_name[0] != '.')
 				break;
 			continue;
-		case 14:
-			if (prefixcmp(de->d_name, "tmp_obj_"))
-				break;
-			prune_tmp_object(path, de->d_name);
-			continue;
 		case 38:
 			sprintf(name, "%02x", i);
 			memcpy(name+2, de->d_name, len+1);
@@ -90,6 +85,10 @@ static int prune_dir(int i, char *path)
 			prune_object(path, de->d_name, sha1);
 			continue;
 		}
+		if (!prefixcmp(de->d_name, "tmp_obj_")) {
+			prune_tmp_object(path, de->d_name);
+			continue;
+		}
 		fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
 	}
 	if (!show_only)
-- 
1.5.6.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Teach fsck and prune that tmp_obj_ file names may not be 14 bytes long
  2008-08-05 18:01 [PATCH] Teach fsck and prune that tmp_obj_ file names may not be 14 bytes long Brandon Casey
@ 2008-08-05 19:07 ` Shawn O. Pearce
  0 siblings, 0 replies; 2+ messages in thread
From: Shawn O. Pearce @ 2008-08-05 19:07 UTC (permalink / raw)
  To: Brandon Casey; +Cc: Junio C Hamano, Git Mailing List

Brandon Casey <casey@nrlssc.navy.mil> wrote:
> As Shawn pointed out, not all temporary file creation routines can
> ensure that the generated temporary file is of a certain length.
> e.g. Java's createTempFile(prefix, suffix). So just depend on the
> prefix 'tmp_obj_' for detection.
> 
> Update prune, and fix the "fix" introduced by a08c53a1 :)

Arrrrgh!  :-)

Thanks for cleaning up my mess.
 
> Signed-off-by: Brandon "appendixless" Casey <casey@nrlssc.navy.mil>
> ---
>  builtin-fsck.c  |    2 +-
>  builtin-prune.c |    9 ++++-----
>  2 files changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/builtin-fsck.c b/builtin-fsck.c
> index 6eb7da8..d3f3de9 100644
> --- a/builtin-fsck.c
> +++ b/builtin-fsck.c
> @@ -385,7 +385,7 @@ static void fsck_dir(int i, char *path)
>  			add_sha1_list(sha1, DIRENT_SORT_HINT(de));
>  			continue;
>  		}
> -		if (prefixcmp(de->d_name, "tmp_obj_"))
> +		if (!prefixcmp(de->d_name, "tmp_obj_"))
>  			continue;
>  		fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
>  	}
> diff --git a/builtin-prune.c b/builtin-prune.c
> index 947de8c..c767a0a 100644
> --- a/builtin-prune.c
> +++ b/builtin-prune.c
> @@ -69,11 +69,6 @@ static int prune_dir(int i, char *path)
>  			if (de->d_name[0] != '.')
>  				break;
>  			continue;
> -		case 14:
> -			if (prefixcmp(de->d_name, "tmp_obj_"))
> -				break;
> -			prune_tmp_object(path, de->d_name);
> -			continue;
>  		case 38:
>  			sprintf(name, "%02x", i);
>  			memcpy(name+2, de->d_name, len+1);
> @@ -90,6 +85,10 @@ static int prune_dir(int i, char *path)
>  			prune_object(path, de->d_name, sha1);
>  			continue;
>  		}
> +		if (!prefixcmp(de->d_name, "tmp_obj_")) {
> +			prune_tmp_object(path, de->d_name);
> +			continue;
> +		}
>  		fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
>  	}
>  	if (!show_only)
> -- 
> 1.5.6.2
> 

-- 
Shawn.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-08-05 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-05 18:01 [PATCH] Teach fsck and prune that tmp_obj_ file names may not be 14 bytes long Brandon Casey
2008-08-05 19:07 ` Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).