From d2680e01d28e8fb1c796bbaff5aa63168a8d8323 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 28 Oct 2009 19:52:58 +0000 Subject: [PATCH] fixes to copy_file() to pass in permissions to open() --- src/file.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 4bb388bd9..112cbc4c1 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -225,13 +225,21 @@ namespace libtorrent ec.assign(errno, boost::system::get_generic_category()); copyfile_state_free(state); #else - int infd = open(inf.c_str(), O_RDONLY); + int infd = ::open(inf.c_str(), O_RDONLY); if (infd < 0) { ec.assign(errno, boost::system::get_generic_category()); return; } - int outfd = open(newf.c_str(), O_WRONLY | O_CREAT); + + // rely on default umask to filter x and w permissions + // for group and others + // TODO: copy the mode from the source file + int permissions = S_IRUSR | S_IWUSR + | S_IRGRP | S_IWGRP + | S_IROTH | S_IWOTH; + + int outfd = ::open(newf.c_str(), O_WRONLY | O_CREAT, permissions); if (outfd < 0) { close(infd); @@ -408,7 +416,7 @@ namespace libtorrent #endif // UNICODE #else char cwd[TORRENT_MAX_PATH]; - getcwd(cwd, sizeof(cwd)); + if (getcwd(cwd, sizeof(cwd)) == 0) return "/"; #endif #if defined TORRENT_WINDOWS && defined UNICODE return convert_from_wstring(cwd);