mirror of https://gitee.com/openkylin/glib2.0.git
vfat文件超过4G移动或复制直接报错
=================================================================== Gbp-Pq: Name 20210325-file-type.patch
This commit is contained in:
parent
977a1a1598
commit
2c21bc1043
70
gio/gfile.c
70
gio/gfile.c
|
@ -55,6 +55,9 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "gfile.h"
|
||||
#include "glib/gstdio.h"
|
||||
|
@ -378,6 +381,29 @@ static gboolean g_file_real_measure_disk_usage_finish (GFile
|
|||
guint64 *num_files,
|
||||
GError **error);
|
||||
|
||||
static const char* get_fs_type (char* path)
|
||||
{
|
||||
const char* fs_type = NULL;
|
||||
struct mntent* m = NULL;
|
||||
FILE* f = NULL;
|
||||
|
||||
f = setmntent ("/etc/mtab", "r");
|
||||
if (!f) {
|
||||
syslog (LOG_ERR, "error:%s", strerror(errno));
|
||||
}
|
||||
|
||||
while ((m = getmntent(f))) {
|
||||
if (!path) continue;
|
||||
if (!m->mnt_dir) continue;
|
||||
if (!strcmp (path, m->mnt_dir)) {
|
||||
fs_type = g_strdup_printf("%s", m->mnt_type);
|
||||
}
|
||||
}
|
||||
endmntent (f);
|
||||
|
||||
return fs_type;
|
||||
}
|
||||
|
||||
typedef GFileIface GFileInterface;
|
||||
G_DEFINE_INTERFACE (GFile, g_file, G_TYPE_OBJECT)
|
||||
|
||||
|
@ -3522,10 +3548,32 @@ g_file_copy (GFile *source,
|
|||
GFileIface *iface;
|
||||
GError *my_error;
|
||||
gboolean res;
|
||||
const char* fs_type;
|
||||
GMount* destination_mount;
|
||||
GFile* root;
|
||||
struct stat s;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (source), FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (destination), FALSE);
|
||||
|
||||
destination_mount = g_file_find_enclosing_mount(g_file_get_parent(destination), NULL, NULL);
|
||||
if ( destination_mount != NULL) {
|
||||
root = g_mount_get_default_location (destination_mount);
|
||||
fs_type = get_fs_type (g_file_get_path(root));
|
||||
if(fs_type != NULL) {
|
||||
if(!strcmp(fs_type,"vfat") || !strcmp(fs_type,"fat32")) {
|
||||
if (stat(g_file_get_path(source), &s) == 0) {
|
||||
if(s.st_size > 4294967296) {
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("The file is too large, the fat format file system only supports files within 4G,can be imported in device after compression"));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_free(fs_type);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
|
@ -3724,10 +3772,32 @@ g_file_move (GFile *source,
|
|||
GFileIface *iface;
|
||||
GError *my_error;
|
||||
gboolean res;
|
||||
const char* fs_type;
|
||||
GMount* destination_mount;
|
||||
GFile* root;
|
||||
struct stat s;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (source), FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (destination), FALSE);
|
||||
|
||||
destination_mount = g_file_find_enclosing_mount(g_file_get_parent(destination), NULL, NULL);
|
||||
if ( destination_mount != NULL) {
|
||||
root = g_mount_get_default_location (destination_mount);
|
||||
|
||||
fs_type = get_fs_type (g_file_get_path(root));
|
||||
if(fs_type != NULL) {
|
||||
if(!strcmp(fs_type,"vfat") || !strcmp(fs_type,"fat32")) {
|
||||
if (stat(g_file_get_path(source), &s) == 0) {
|
||||
if(s.st_size > 4294967296) {
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("The file is too large, the fat format file system only supports files within 4G,can be moved in device after compression"));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_free(fs_type);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue