From 9cda9ad1769e835f1b77662fa3de7580788880a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 31 Mar 2013 06:24:30 +0000 Subject: [PATCH] [ARCHIVER] * BUG: The previous fix was incorrect. We can now really create an executable when the project directory and the target directory are not on the same device. git-svn-id: svn://localhost/gambas/trunk@5604 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbc/gbc_archive.c | 13 +++++-------- main/share/gb_file_temp.h | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/main/gbc/gbc_archive.c b/main/gbc/gbc_archive.c index e39e55020..1bc753110 100644 --- a/main/gbc/gbc_archive.c +++ b/main/gbc/gbc_archive.c @@ -112,9 +112,9 @@ static void make_executable(void) const char *err; struct stat info; - FILE_chdir(FILE_get_dir(ARCH_project)); + FILE_chdir(FILE_get_dir(ARCH_output)); - // If we cannot make the archive executable, just print a warning. gbs create an executable cache + // If we cannot make the archive executable, just print a warning. gbs creates an executable cache // inside /tmp, and /tmp may be mounted with the "noexec" flag. if (stat(TEMP_EXEC, &info) || chmod(TEMP_EXEC, info.st_mode | S_IXUSR | S_IXGRP | S_IXOTH)) @@ -130,11 +130,8 @@ static void make_executable(void) if (rename(TEMP_EXEC, ARCH_output)) { - if (FILE_copy(TEMP_EXEC, ARCH_output)) - { - err = "Cannot create executable"; - goto __ERROR; - } + err = "Cannot create executable"; + goto __ERROR; } return; @@ -196,7 +193,7 @@ void ARCH_init(void) ALLOC(&arch_buffer, ARCH_BUFFER_SIZE); - arch_file = fopen(".temp.gambas", "w"); + arch_file = fopen(FILE_cat(FILE_get_dir(ARCH_output), TEMP_EXEC, NULL), "w"); if (arch_file == NULL) THROW("Cannot create temporary archive file: &1", ARCH_output); diff --git a/main/share/gb_file_temp.h b/main/share/gb_file_temp.h index 2169a6776..e7fe1e130 100644 --- a/main/share/gb_file_temp.h +++ b/main/share/gb_file_temp.h @@ -1046,14 +1046,24 @@ bool FILE_copy(const char *src, const char *dst) ssize_t len; char *buf = NULL; int save_errno; + struct stat info; - src_fd = open(src, O_RDONLY); - if (src_fd < 0) + fprintf(stderr, "FILE_copy: %s -> %s\n", src, dst); + + if (stat(src, &info)) return TRUE; - dst_fd = open(dst, O_WRONLY); + src_fd = open(src, O_RDONLY); + if (src_fd < 0) + { + fprintf(stderr, "open src failed\n"); + return TRUE; + } + + dst_fd = creat(dst, info.st_mode); if (dst_fd < 0) { + fprintf(stderr, "open dst failed\n"); save_errno = errno; close(src_fd); errno = save_errno;