Add 'filesize' call.

Returns the size of a file.  You can already do this with 'stat',
but this call is good for scripting.
This commit is contained in:
Richard Jones
2010-01-25 11:34:56 +00:00
parent c9324c2025
commit 306077ac96
3 changed files with 31 additions and 1 deletions

View File

@@ -520,3 +520,21 @@ do_zfile (const char *method, const char *path)
return strdup (line);
}
int64_t
do_filesize (const char *path)
{
int r;
struct stat buf;
CHROOT_IN;
r = stat (path, &buf); /* follow symlinks */
CHROOT_OUT;
if (r == -1) {
reply_with_perror ("filesize: %s", path);
return -1;
}
return buf.st_size;
}

View File

@@ -1 +1 @@
217
218

View File

@@ -4188,6 +4188,18 @@ If the destination is a device, it must be as large or larger
than the source file or device, otherwise the copy will fail.
This command cannot do partial copies.");
("filesize", (RInt64 "size", [Pathname "file"]), 218, [],
[InitBasicFS, Always, TestOutputInt (
[["write_file"; "/file"; "hello, world"; "0"];
["filesize"; "/file"]], 12)],
"return the size of the file in bytes",
"\
This command returns the size of C<file> in bytes.
To get other stats about a file, use C<guestfs_stat>, C<guestfs_lstat>,
C<guestfs_is_dir>, C<guestfs_is_file> etc.
To get the size of block devices, use C<guestfs_blockdev_getsize64>.");
]
let all_functions = non_daemon_functions @ daemon_functions