cmd_get.h \
cmd_help.c \
cmd_help.h \
+ cmd_info.c \
+ cmd_info.h \
cmd_lcd.c \
cmd_lcd.h \
cmd_ls.c \
--- /dev/null
+/* $Id$
+ * client cmdline interface command "info" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <glib/gerror.h>
+#include <popt.h>
+#include <stdlib.h>
+#include <string.h>
+#include "captive/client-file.h"
+
+#include "cmd_info.h" /* self */
+#include "cmd_cd.h" /* for cmdline_path_from_cwd() */
+#include "main.h"
+#include "file_info.h"
+
+
+GQuark cmdline_cmd_info_error_quark(void)
+{
+GQuark r=0;
+
+ if (!r)
+ r=g_quark_from_static_string("cmdline-cmd-info");
+
+ return r;
+}
+
+
+const struct poptOption cmd_info_table[]={
+ POPT_AUTOHELP
+ POPT_TABLEEND
+ };
+
+
+void cmd_info(const char **cmd_argv,GError **errp)
+{
+CaptiveFileObject *captive_file_object;
+GnomeVFSFileInfo file_info;
+const gchar *filepath;
+
+ g_return_if_fail(!errp || !*errp);
+
+ filepath=cmdline_path_from_cwd(cmd_argv[0]);
+
+ if (!errvfsresult_to_gerr(errp,captive_file_new_open(
+ &captive_file_object, /* captive_file_object_return */
+ filepath, /* pathname */
+ GNOME_VFS_OPEN_READ))) { /* mode */
+ err_cleanup(errp);
+ g_set_error(errp,CMDLINE_CMD_INFO_ERROR,CMDLINE_CMD_INFO_ERROR_CANNOT_OPEN_FILE,
+ _("Cannot open file: %s"),filepath);
+ return;
+ }
+
+ if (!errvfsresult_to_gerr(errp,captive_file_file_info_get(
+ captive_file_object, /* captive_file_object */
+ &file_info))) { /* file_info */
+ err_cleanup(errp);
+ g_set_error(errp,CMDLINE_CMD_INFO_ERROR,CMDLINE_CMD_INFO_ERROR_GETTING_FILE_INFO,
+ _("Cannot get file information about: %s"),filepath);
+ goto err_unref;
+ }
+ file_info_dump_full(&file_info,errp);
+ if (*errp)
+ goto err_unref;
+
+err_unref:
+ g_object_unref(captive_file_object);
+}
--- /dev/null
+/* $Id$
+ * Include file for client cmdline interface command "info" for libcaptive
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_CMDLINE_CMD_INFO_H
+#define _CAPTIVE_CLIENT_CMDLINE_CMD_INFO_H 1
+
+
+#include <glib/gerror.h>
+#include <popt.h>
+
+
+#define CMDLINE_CMD_INFO_ERROR (cmdline_cmd_info_error_quark())
+GQuark cmdline_cmd_info_error_quark(void);
+
+typedef enum {
+ CMDLINE_CMD_INFO_ERROR_CANNOT_OPEN_FILE,
+ CMDLINE_CMD_INFO_ERROR_GETTING_FILE_INFO,
+ } CmdlineCmdInfoError;
+
+
+extern const struct poptOption cmd_info_table[];
+
+void cmd_info(const char **cmd_argv,GError **errp);
+
+
+#endif /* _CAPTIVE_CLIENT_CMDLINE_CMD_INFO_H */
#include <libgnomevfs/gnome-vfs-file-info.h>
#include <glib/gstrfuncs.h>
#include <stdio.h>
+#include <time.h>
#include "file_info.h" /* self */
g_free(file_size);
}
+
+
+void file_info_dump_full(const GnomeVFSFileInfo *file_info,GError **errp)
+{
+ g_return_if_fail(!errp || !*errp);
+
+ printf("Filename: %s\n",file_info->name);
+
+ fputs("File type: ",stdout);
+ switch (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) ? GNOME_VFS_FILE_TYPE_UNKNOWN : file_info->type) {
+ case GNOME_VFS_FILE_TYPE_REGULAR: puts("REGULAR"); break;
+ case GNOME_VFS_FILE_TYPE_DIRECTORY: puts("DIRECTORY"); break;
+ case GNOME_VFS_FILE_TYPE_SOCKET: puts("SOCKET"); break;
+ default: puts("???"); break;
+ }
+
+ fputs("File size: ",stdout);
+ if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)
+ printf("%" GNOME_VFS_SIZE_FORMAT_STR "\n",file_info->size);
+ else
+ puts("???");
+
+ fputs("Block count: ",stdout);
+ if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)
+ printf("%" GNOME_VFS_SIZE_FORMAT_STR "\n",file_info->block_count);
+ else
+ puts("???");
+
+ fputs("Writable?: ",stdout);
+ if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS))
+ puts("???");
+ else if (file_info->permissions & GNOME_VFS_PERM_USER_WRITE)
+ puts("read/write");
+ else
+ puts("read/only");
+
+ fputs("Access-time (atime): ",stdout);
+ if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ATIME))
+ puts("???");
+ else
+ fputs(ctime(&file_info->atime),stdout);
+
+ fputs("Modification-time (mtime): ",stdout);
+ if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME))
+ puts("???");
+ else
+ fputs(ctime(&file_info->mtime),stdout);
+
+ fputs("Change-time (ctime): ",stdout);
+ if (!(file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_CTIME))
+ puts("???");
+ else
+ fputs(ctime(&file_info->ctime),stdout);
+}
void file_info_dump_line(const GnomeVFSFileInfo *file_info,GError **errp);
+void file_info_dump_full(const GnomeVFSFileInfo *file_info,GError **errp);
#endif /* _CAPTIVE_CLIENT_CMDLINE_FILE_INFO_H */
#include "cmd_ls.h"
#include "cmd_get.h"
#include "cmd_put.h"
+#include "cmd_info.h"
#include "cmd_rm.h"
#include "cmd_mv.h"
#include "cmd_mkdir.h"
{ "ls" ,N_("Directory[1] listing.") ,cmd_ls_table ,cmd_ls ,0,1 },
{ "get" ,N_("Copy guest-os file[1] to host-os (opt. file[2]).") ,cmd_get_table ,cmd_get ,1,2 },
{ "put" ,N_("Copy host-os file[1] to guest-os (opt. file[2]).") ,cmd_put_table ,cmd_put ,1,2 },
+ { "info" ,N_("Query information about guest-os item[1].") ,cmd_info_table ,cmd_info ,1,1 },
{ "rm" ,N_("Remove guest-os file[1].") ,cmd_rm_table ,cmd_rm ,1,1 },
{ "mv" ,N_("Move (rename) guest-os item[1] to guest-os item[2]."),cmd_mv_table ,cmd_mv ,2,2 },
{ "mkdir",N_("Create guest-os directory[1].") ,cmd_mkdir_table,cmd_mkdir,1,1 },