Patch: parse 2 GB files correctly in ftp-method.c



Hi,

I just submitted a patch for this:

http://bugzilla.gnome.org/show_bug.cgi?id=338893

It fixes gnome_vfs_parse_ls_lga() to parse larger-than-32-bit file sizes
correctly.  Also, it fixes the various HAVE_STRUCT_STAT_* macros there;
we didn't check for them correctly in configure.in, and we weren't
really using the right macros --- this makes that function fill in
st_blocks correctly, for example.

Is this OK to commit?

  Federico
https://bugzilla.novell.com/show_bug.cgi?id=171156

2006-05-02  Federico Mena Quintero  <federico novell com>

	Fix http://bugzilla.gnome.org/show_bug.cgi?id=338893: file size is
	reported wrong in the FTP method for files larger than 2 GB.

	* configure.in.orig: Check for atoll() to AC_CHECK_FUNCS().
	Check for stat.st_blksize stat.st_rdev, and AC_STRUCT_ST_BLOCKS
	(without these, we were never entering the corresponding #ifdef
	blocks in gnome-vfs-parse-ls.c, and thus not filling in certain
	fields of struct stat).

	* libgnomevfs/gnome-vfs-parse-ls.c (gnome_vfs_parse_ls_lga): Use
	atoll() when available for stat.st_size, or atof() if it's not
	available.  Use HAVE_STRUCT_STAT_ST_RDEV,
	HAVE_STRUCT_STAT_ST_BLOCKS, and HAVE_STRUCT_STAT_ST_BLKSIZE instead of
	HAVE_ST_RDEV, HAVE_ST_BLOCKS, and HAVE_ST_BLKSIZE, respectively.

	* programs/gnomevfs-ls.c (show_data): Use
	GNOME_VFS_SIZE_FORMAT_STR for info->size, not "%ld".

--- gnome-vfs/configure.in.orig	2006-05-02 19:21:49.000000000 -0500
+++ gnome-vfs/configure.in	2006-05-02 19:22:02.000000000 -0500
@@ -159,7 +159,9 @@ AC_SEARCH_LIBS(gethostent, nsl)
 AC_SEARCH_LIBS(setsockopt, socket)
 
 AC_FUNC_ALLOCA
-AC_CHECK_FUNCS(getdtablesize open64 lseek64 statfs statvfs seteuid setegid setresuid setresgid readdir_r mbrtowc inet_pton getdelim sysctlbyname poll posix_fadvise fchmod)
+AC_CHECK_FUNCS(getdtablesize open64 lseek64 statfs statvfs seteuid setegid setresuid setresgid readdir_r mbrtowc inet_pton getdelim sysctlbyname poll posix_fadvise fchmod atoll)
+AC_CHECK_MEMBERS([struct stat.st_blksize, struct stat.st_rdev])
+AC_STRUCT_ST_BLOCKS
 
 dnl Volume monitor stuff			     
 AC_CHECK_FUNCS(setmntent endmntent hasmntopt getmntinfo)
--- gnome-vfs/libgnomevfs/gnome-vfs-parse-ls.c.orig	2006-05-02 15:10:20.000000000 -0500
+++ gnome-vfs/libgnomevfs/gnome-vfs-parse-ls.c	2006-05-02 15:18:11.000000000 -0500
@@ -595,7 +595,7 @@ gnome_vfs_parse_ls_lga (const char *p,
 		    || sscanf (columns [idx2], " %d", &min) != 1)
 			goto error;
 	
-#ifdef HAVE_ST_RDEV
+#ifdef HAVE_STRUCT_STAT_ST_RDEV
 		/* Starting from linux 2.6, minor number is split between bits 
 		 * 0-7 and 20-31 of dev_t. This calculation is also valid
 		 * on older kernel with 8 bit minor and major numbers 
@@ -611,9 +611,13 @@ gnome_vfs_parse_ls_lga (const char *p,
 		/* Common file size */
 		if (!is_num (columns[idx2]))
 			goto error;
-	
-		s->st_size = (gsize) atol (columns [idx2]);
-#ifdef HAVE_ST_RDEV
+
+#ifdef HAVE_ATOLL
+		s->st_size = (off_t) atoll (columns [idx2]);
+#else
+		s->st_size = (off_t) atof (columns [idx2]);
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_RDEV
 		s->st_rdev = 0;
 #endif
 	}
@@ -625,10 +629,10 @@ gnome_vfs_parse_ls_lga (const char *p,
 	s->st_atime = s->st_ctime = s->st_mtime;
 	s->st_dev = 0;
 	s->st_ino = 0;
-#ifdef HAVE_ST_BLKSIZE
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
 	s->st_blksize = 512;
 #endif
-#ifdef HAVE_ST_BLOCKS
+#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
 	s->st_blocks = (s->st_size + 511) / 512;
 #endif
 
--- gnome-vfs/programs/gnomevfs-ls.c.orig	2006-05-02 15:45:56.000000000 -0500
+++ gnome-vfs/programs/gnomevfs-ls.c	2006-05-02 19:11:07.000000000 -0500
@@ -63,7 +63,7 @@ show_data (gpointer item, gpointer no_it
 
 	path = g_strconcat (directory, "/", info->name, NULL);
 
-	g_print ("%s\t%s%s%s\t(%s, %s)\tsize %ld\tmode %04o\n",
+	g_print ("%s\t%s%s%s\t(%s, %s)\tsize %" GNOME_VFS_SIZE_FORMAT_STR "\tmode %04o\n",
 			info->name,
 			GNOME_VFS_FILE_INFO_SYMLINK (info) ? " [link: " : "",
 			GNOME_VFS_FILE_INFO_SYMLINK (info) ? info->symlink_name
@@ -71,7 +71,7 @@ show_data (gpointer item, gpointer no_it
 			GNOME_VFS_FILE_INFO_SYMLINK (info) ? " ]" : "",
 			type_to_string (info->type),
 			info->mime_type,
-			(glong) info->size,
+			info->size,
 			info->permissions);
 
 	g_free (path);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]