1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -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; struct stat statbuf;
char *fname, *tempfname; char *fname, *tempfname;
int temphandle, old_umask; int ret, temphandle, old_umask;
if (net_geterror(dcc->handle) != 0) { if (net_geterror(dcc->handle) != 0) {
/* error connecting */ /* error connecting */
@ -215,13 +215,23 @@ static void sig_dccget_connected(GET_DCC_REC *dcc)
temphandle = mkstemp(tempfname); temphandle = mkstemp(tempfname);
umask(old_umask); umask(old_umask);
dcc->fhandle = -1; if (temphandle == -1)
if (link(tempfname, dcc->file) == 0) { ret = -1;
/* ok, we're the file owner now */ else {
dcc->fhandle = open(dcc->file, O_WRONLY | O_TRUNC | O_CREAT, ret = link(tempfname, dcc->file);
dcc_file_create_mode); 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/remove the temp file */
close(temphandle); close(temphandle);
unlink(tempfname); unlink(tempfname);