From 14643408e8b1acfc32668de5e1f7263351a24480 Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Sun, 15 Jan 2012 05:04:29 +0000 Subject: [PATCH] WINGs: Make fetchFile() more similar to copyFile() from getstyle.c The idea is to use the fetchFile() in getstyle.c and in wcolorpanel.c instead of using two very similar functions. In order to do that, let's move the most generic one (fetchFile()) to libWUtils, and this is the first step. --- WINGs/wcolorpanel.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c index c86dfdd7..eb019470 100644 --- a/WINGs/wcolorpanel.c +++ b/WINGs/wcolorpanel.c @@ -3342,8 +3342,16 @@ static int fetchFile(char *toPath, char *srcFile, char *destFile) FILE *src, *dst; size_t nread, nwritten; char *dstpath; + struct stat st; char buf[BUFSIZE]; + /* only to a directory */ + if (stat(toPath, &st) != 0 || !S_ISDIR(st.st_mode)) + return -1; + /* only copy files */ + if (stat(srcFile, &st) != 0 || !S_ISREG(st.st_mode)) + return -1; + RETRY( src = fopen(srcFile, "rb") ) if (src == NULL) { werror(_("Could not open %s"), srcFile); @@ -3374,10 +3382,11 @@ static int fetchFile(char *toPath, char *srcFile, char *destFile) unlink(dstpath); RETRY( fclose(src) ) + fchmod(fileno(dst), st.st_mode); fsync(fileno(dst)); RETRY( fclose(dst) ) - wfree(dstpath); + return 0; }