summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-03-17 00:59:46 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-03-17 00:59:46 +0000
commit0a02833d0e566683166e13519b246fc40a3fc74d (patch)
treea0f122288d437017e51f754419393a58ff0c32ec /src/irc
parentf03280ace08e4ef2e2c2787c9fabd3e0203a00b5 (diff)
downloadirssi-0a02833d0e566683166e13519b246fc40a3fc74d.zip
fallback to rename() if link() isn't supported on the filesystem, so people
can still download files to such FSes.. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2625 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/dcc/dcc-get.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/irc/dcc/dcc-get.c b/src/irc/dcc/dcc-get.c
index d13f8376..381d02b1 100644
--- a/src/irc/dcc/dcc-get.c
+++ b/src/irc/dcc/dcc-get.c
@@ -176,7 +176,7 @@ static void sig_dccget_connected(GET_DCC_REC *dcc)
{
struct stat statbuf;
char *fname, *tempfname;
- int temphandle, old_umask;
+ int ret, temphandle, old_umask;
if (net_geterror(dcc->handle) != 0) {
/* error connecting */
@@ -215,13 +215,23 @@ static void sig_dccget_connected(GET_DCC_REC *dcc)
temphandle = mkstemp(tempfname);
umask(old_umask);
- dcc->fhandle = -1;
- if (link(tempfname, dcc->file) == 0) {
- /* ok, we're the file owner now */
- dcc->fhandle = open(dcc->file, O_WRONLY | O_TRUNC | O_CREAT,
- dcc_file_create_mode);
+ if (temphandle == -1)
+ ret = -1;
+ else {
+ ret = link(tempfname, dcc->file);
+ if (ret == -1 && errno == EPERM) {
+ /* hard links aren't supported - some people
+ want to download stuff to FAT/NTFS/etc
+ partitions, so fallback to rename() */
+ ret = rename(tempfname, dcc->file);
+ }
}
+ /* if ret = 0, we're the file owner now */
+ dcc->fhandle = ret == -1 ? -1 :
+ open(dcc->file, O_WRONLY | O_TRUNC,
+ dcc_file_create_mode);
+
/* close/remove the temp file */
close(temphandle);
unlink(tempfname);