qfile-copy: try to produce only one error message
This commit is contained in:
		
							parent
							
								
									3ed985d220
								
							
						
					
					
						commit
						9f0d84a528
					
				@ -1,8 +1,10 @@
 | 
				
			|||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
#include <ioall.h>
 | 
					#include <ioall.h>
 | 
				
			||||||
 | 
					#include "filecopy.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void notify_progress(int, int);
 | 
					extern void notify_progress(int, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char * copy_file(int outfd, int infd, long long size)
 | 
					int copy_file(int outfd, int infd, long long size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char buf[4096];
 | 
						char buf[4096];
 | 
				
			||||||
	long long written = 0;
 | 
						long long written = 0;
 | 
				
			||||||
@ -15,14 +17,24 @@ char * copy_file(int outfd, int infd, long long size)
 | 
				
			|||||||
			count = size - written;
 | 
								count = size - written;
 | 
				
			||||||
		ret = read(infd, buf, count);
 | 
							ret = read(infd, buf, count);
 | 
				
			||||||
		if (!ret)
 | 
							if (!ret)
 | 
				
			||||||
			return("EOF while reading file");
 | 
								return COPY_FILE_READ_EOF;
 | 
				
			||||||
		if (ret < 0)
 | 
							if (ret < 0)
 | 
				
			||||||
			return("error reading file");
 | 
								return COPY_FILE_READ_ERROR;
 | 
				
			||||||
		if (!write_all(outfd, buf, ret))
 | 
							if (!write_all(outfd, buf, ret))
 | 
				
			||||||
			return("error writing file content");
 | 
								return COPY_FILE_WRITE_ERROR;
 | 
				
			||||||
		notify_progress(ret, 0);
 | 
							notify_progress(ret, 0);
 | 
				
			||||||
		written += ret;
 | 
							written += ret;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return NULL;
 | 
						return COPY_FILE_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char * copy_file_status_to_str(int status)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						switch (status) {
 | 
				
			||||||
 | 
							case COPY_FILE_OK: return "OK";
 | 
				
			||||||
 | 
							case COPY_FILE_READ_EOF: return "Unexpected end of data while reading";
 | 
				
			||||||
 | 
							case COPY_FILE_READ_ERROR: return "Error reading";
 | 
				
			||||||
 | 
							case COPY_FILE_WRITE_ERROR: return "Error writing";
 | 
				
			||||||
 | 
							default: return "????????";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					} 
 | 
				
			||||||
 | 
				
			|||||||
@ -15,4 +15,12 @@ unsigned int mtime;
 | 
				
			|||||||
	unsigned int mtime_nsec;
 | 
						unsigned int mtime_nsec;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char * copy_file(int outfd, int infd, long long size);
 | 
					enum {
 | 
				
			||||||
 | 
						COPY_FILE_OK,
 | 
				
			||||||
 | 
						COPY_FILE_READ_EOF,
 | 
				
			||||||
 | 
						COPY_FILE_READ_ERROR,
 | 
				
			||||||
 | 
						COPY_FILE_WRITE_ERROR
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int copy_file(int outfd, int infd, long long size);
 | 
				
			||||||
 | 
					char *copy_file_status_to_str(int status);
 | 
				
			||||||
 | 
				
			|||||||
@ -50,7 +50,7 @@ void write_headers(struct file_header *hdr, char *filename)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	if (!write_all(1, hdr, sizeof(*hdr))
 | 
						if (!write_all(1, hdr, sizeof(*hdr))
 | 
				
			||||||
	    || !write_all(1, filename, hdr->namelen))
 | 
						    || !write_all(1, filename, hdr->namelen))
 | 
				
			||||||
		gui_fatal("writing file headers to remove AppVM");
 | 
							exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int single_file_processor(char *filename, struct stat *st)
 | 
					int single_file_processor(char *filename, struct stat *st)
 | 
				
			||||||
@ -67,15 +67,21 @@ int single_file_processor(char *filename, struct stat *st)
 | 
				
			|||||||
	hdr.mtime_nsec = st->st_mtim.tv_nsec;
 | 
						hdr.mtime_nsec = st->st_mtim.tv_nsec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (S_ISREG(mode)) {
 | 
						if (S_ISREG(mode)) {
 | 
				
			||||||
		char *ret;
 | 
							int ret;
 | 
				
			||||||
		fd = open(filename, O_RDONLY);
 | 
							fd = open(filename, O_RDONLY);
 | 
				
			||||||
		if (!fd)
 | 
							if (!fd)
 | 
				
			||||||
			gui_fatal("open %s", filename);
 | 
								gui_fatal("open %s", filename);
 | 
				
			||||||
		hdr.filelen = st->st_size;
 | 
							hdr.filelen = st->st_size;
 | 
				
			||||||
		write_headers(&hdr, filename);
 | 
							write_headers(&hdr, filename);
 | 
				
			||||||
		ret = copy_file(1, fd, hdr.filelen);
 | 
							ret = copy_file(1, fd, hdr.filelen);
 | 
				
			||||||
		if (ret)
 | 
							// if COPY_FILE_WRITE_ERROR, hopefully remote will produce a message
 | 
				
			||||||
			gui_fatal("Copying file %s: %s", filename, ret);
 | 
							if (ret != COPY_FILE_OK) {
 | 
				
			||||||
 | 
								if (ret != COPY_FILE_WRITE_ERROR)
 | 
				
			||||||
 | 
									gui_fatal("Copying file %s: %s", filename,
 | 
				
			||||||
 | 
										  copy_file_status_to_str(ret));
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									exit(1);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		close(fd);
 | 
							close(fd);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (S_ISDIR(mode)) {
 | 
						if (S_ISDIR(mode)) {
 | 
				
			||||||
@ -89,7 +95,7 @@ int single_file_processor(char *filename, struct stat *st)
 | 
				
			|||||||
		hdr.filelen = st->st_size + 1;
 | 
							hdr.filelen = st->st_size + 1;
 | 
				
			||||||
		write_headers(&hdr, filename);
 | 
							write_headers(&hdr, filename);
 | 
				
			||||||
		if (!write_all(1, name, st->st_size + 1))
 | 
							if (!write_all(1, name, st->st_size + 1))
 | 
				
			||||||
			gui_fatal("write to remote VM");
 | 
								exit(1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -130,7 +136,7 @@ void send_vmname(char *vmname)
 | 
				
			|||||||
	memset(buf, 0, sizeof(buf));
 | 
						memset(buf, 0, sizeof(buf));
 | 
				
			||||||
	strncat(buf, vmname, sizeof(buf) - 1);
 | 
						strncat(buf, vmname, sizeof(buf) - 1);
 | 
				
			||||||
	if (!write_all(1, buf, sizeof buf))
 | 
						if (!write_all(1, buf, sizeof buf))
 | 
				
			||||||
		gui_fatal("writing vmname to remote VM");
 | 
							exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *get_item(char *data, char **current, int size)
 | 
					char *get_item(char *data, char **current, int size)
 | 
				
			||||||
 | 
				
			|||||||
@ -43,6 +43,7 @@ done
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
qdbus $REF close
 | 
					qdbus $REF close
 | 
				
			||||||
rm -f $PROGRESS_FILE
 | 
					rm -f $PROGRESS_FILE
 | 
				
			||||||
if ! [ "x"$agentstatus = xDONE ] ; then 
 | 
					# we do not want a dozen error messages, do we
 | 
				
			||||||
	kdialog --sorry 'Abnormal file copy termination; see /var/log/qubes/qrexec.xid.log in dom0 for more details'
 | 
					# if ! [ "x"$agentstatus = xDONE ] ; then 
 | 
				
			||||||
fi
 | 
					# 	kdialog --sorry 'Abnormal file copy termination; see /var/log/qubes/qrexec.xid.log in dom0 for more details'
 | 
				
			||||||
 | 
					# fi
 | 
				
			||||||
 | 
				
			|||||||
@ -38,14 +38,19 @@ void fix_times_and_perms(struct file_header *hdr, char *name)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void process_one_file_reg(struct file_header *hdr, char *name)
 | 
					void process_one_file_reg(struct file_header *hdr, char *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char *ret;
 | 
						int ret;
 | 
				
			||||||
	int fdout =
 | 
						int fdout =
 | 
				
			||||||
	    open(name, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, 0700);
 | 
						    open(name, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, 0700);
 | 
				
			||||||
	if (fdout < 0)
 | 
						if (fdout < 0)
 | 
				
			||||||
		do_exit(errno);
 | 
							do_exit(errno);
 | 
				
			||||||
	ret = copy_file(fdout, 0, hdr->filelen);
 | 
						ret = copy_file(fdout, 0, hdr->filelen);
 | 
				
			||||||
	if (ret)
 | 
						if (ret != COPY_FILE_OK) {
 | 
				
			||||||
 | 
							if (ret == COPY_FILE_READ_EOF
 | 
				
			||||||
 | 
							    || ret == COPY_FILE_READ_ERROR)
 | 
				
			||||||
 | 
								do_exit(LEGAL_EOF);	// hopefully remote will produce error message
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
			do_exit(errno);
 | 
								do_exit(errno);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	close(fdout);
 | 
						close(fdout);
 | 
				
			||||||
	fix_times_and_perms(hdr, name);
 | 
						fix_times_and_perms(hdr, name);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -68,7 +73,7 @@ void process_one_file_link(struct file_header *hdr, char *name)
 | 
				
			|||||||
	if (hdr->filelen > MAX_PATH_LENGTH - 1)
 | 
						if (hdr->filelen > MAX_PATH_LENGTH - 1)
 | 
				
			||||||
		do_exit(ENAMETOOLONG);
 | 
							do_exit(ENAMETOOLONG);
 | 
				
			||||||
	if (!read_all(0, content, hdr->filelen))
 | 
						if (!read_all(0, content, hdr->filelen))
 | 
				
			||||||
		do_exit(errno);
 | 
							do_exit(LEGAL_EOF);	// hopefully remote has produced error message
 | 
				
			||||||
	content[hdr->filelen] = 0;
 | 
						content[hdr->filelen] = 0;
 | 
				
			||||||
	if (symlink(content, name))
 | 
						if (symlink(content, name))
 | 
				
			||||||
		do_exit(errno);
 | 
							do_exit(errno);
 | 
				
			||||||
@ -80,7 +85,7 @@ void process_one_file(struct file_header *hdr)
 | 
				
			|||||||
	if (hdr->namelen > MAX_PATH_LENGTH - 1)
 | 
						if (hdr->namelen > MAX_PATH_LENGTH - 1)
 | 
				
			||||||
		do_exit(ENAMETOOLONG);
 | 
							do_exit(ENAMETOOLONG);
 | 
				
			||||||
	if (!read_all(0, namebuf, hdr->namelen))
 | 
						if (!read_all(0, namebuf, hdr->namelen))
 | 
				
			||||||
		do_exit(errno);
 | 
							do_exit(LEGAL_EOF);	// hopefully remote has produced error message
 | 
				
			||||||
	namebuf[hdr->namelen] = 0;
 | 
						namebuf[hdr->namelen] = 0;
 | 
				
			||||||
	if (S_ISREG(hdr->mode))
 | 
						if (S_ISREG(hdr->mode))
 | 
				
			||||||
		process_one_file_reg(hdr, namebuf);
 | 
							process_one_file_reg(hdr, namebuf);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user