1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

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
This commit is contained in:
Timo Sirainen 2002-03-17 00:59:46 +00:00 committed by cras
parent f03280ace0
commit 0a02833d0e

View File

@ -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);