Commit Graph

32 Commits

Author SHA1 Message Date
Mike Gelfand db3d40d0ed Switch to clang-format for code formatting, include Mac client 2021-08-16 00:38:29 +03:00
RobCrowston 0155252823
Add in-kernel file copying for several platforms. (#1092)
* Add in-kernel copying support for Linux (sendfile64(2), copy_file_range(2)), FreeBSD 13 (copy_file_range(2)), MacOS (copyfile(2)), and Windows (CopyFileExA).

* Fix macro name USE_COPY_FILE_RANGE.

* Minor bugfixes for userspace fallback.

* Fix linux sendfile64 bugs.

* Remove some overzealous asserts.

* Allow transmission-test-copy to take an optional argument for an external reference file.

* Fix return value error of tr_sys_path_copy.

* Use COPYFILE_ALL for Macs without COPYFILE_CLONE.

* Add in-kernel file copying for several platforms.

Numerous operating systems now have support for copying files directly in the
kernel, which is generally more efficient than copying in a userspace read(2)/
write(2) loop. (This becomes particularly relevant for 4th gen PCI-E storage,
which approaches the latency of DRAM.) For Linux I use sendfile64(2), and, for
later kernels, copy_file_range(2). FreeBSD 13 will also support
copy_file_range(2). MacOS has copyfile(2), and Windows has CopyFileExA.
Operating systems lacking such a syscall continue to use the existing
read(2)/write(2) loop.

* Appease uncrustify.

* Appease uncrustify.

* copy-test: generate random content at run time.

* copy-test: Stylistic changes and more check()s.

* copy-test: files_are_identical should follow test idioms

* tr_sys_path_copy: numerous tweaks as requested by review.

* s/old file/source file; s/new file/destination file.

* tr_sys_path_copy: handle win32 wide characters in paths.

* Uncrustify.

* test-copy: Use non-string create_file_with_contents.

* tr_sys_path_copy: numerous fixes.

Per review: generate test file content at runtime; tidy use of check();
fix style; re-measure file sizes in the copy; define a macro when the
system does not provide it; use Unicode APIs on Windows; and fix
documentation.

* Updated as per comments.

* Rebase kernel-copy changes onto 3.0 with gtest.

* Undo irrelevant comment change.

* Fix syntax error.

* Use tr_malloc() instead of tr_valloc().

* Use EXPECT instead of TR_ASSERT in gtest.

* Add error handling.

* Acceptable coding style has changed again.

Now it's camelCase. Also use nullptr instead of NULL, etc.

* Fix east/west const.

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
2021-08-07 12:04:03 +03:00
Mike Gelfand 75458d6be3 Make use of TR_UNUSED macro where cast-to-void was used before 2020-08-18 14:34:49 +03:00
Mike Gelfand 35ed02a1fd Use explicit boolean conversions (follow-up) 2019-07-14 22:57:40 +03:00
Mike Gelfand a3e4919385 Introduce `tr_str_is_empty` to relay intent better 2019-07-13 12:00:06 +03:00
Mike Gelfand 3106675261 Fix UNC paths resolution on Windows
While resolved paths always contain the	`\\?\` prefix, it's not	always
correct	to strip only those 4 chars. In	case of	UNC paths, the prefix
is actually a bit longer (`\\?\UNC\`) and needs	to be replaced with `\\`
instead.

Failing	to do so results in invalid paths, e.g.	`\\Host\Share\File` becomes
`UNC\Host\Share\File` which totally wrong.
2018-01-24 23:45:08 +03:00
Mike Gelfand 30c7c05cbb Refactor completion scripts execution
There're still a few issues here and there, but overall I believe it's now
better than it was before.
2017-11-28 10:03:08 +03:00
Mike Gelfand 580c5e4166 Rename `tr_sys_file_prefetch` to `tr_sys_file_advise`
New function now supports two flags: will need and don't need.
2017-07-08 16:09:37 +03:00
Mike Gelfand 28c872af1e Change `tr_sys_file_prefetch` behavior a bit
Return true by default. Only return false if we did in fact perform some
action and it failed.
2017-07-08 12:51:36 +03:00
Mike Gelfand deea6fc6a2 Bring assertions closer to the beginning of blocks 2017-06-13 07:44:09 +03:00
Mike Gelfand 98695fe3c1 Introduce our own assertion macros with finer control 2017-06-08 10:24:12 +03:00
Mike Gelfand 1e3d20422a Reduce for loop variables scope 2017-05-14 01:38:31 +03:00
Mike Gelfand 87220d44a5 Fix FTBFS on Windows (oops!) 2017-05-01 19:08:30 +03:00
Mike Gelfand 14370e5353 Fix a number of other style inconsistencies met along the way (part 2) 2017-05-01 18:47:49 +03:00
Mike Gelfand 4f9d9ad92b Code style change leftovers
For some reason, GTK client wasn't fully processed. All the rest of changes
are mostly in comments.
2017-04-21 10:40:57 +03:00
Mike Gelfand dadffa2c0f Align type qualifiers to the right (code style)
This way all the qualifiers (`const`, `volatile`, `mutable`) are grouped
together, e.g. `T const* const x` vs. `const T* const x`. Also helps reading
types right-to-left, e.g. "constant pointer to constant T" vs. "constant
pointer to T which is constant".
2017-04-20 19:53:20 +03:00
Mike Gelfand d7930984ef Adjust uncrustify config, reformat all but Mac client
There're places where manual intervention is still required as uncrustify
is not ideal (unfortunately), but at least one may rely on it to do the
right thing most of the time (e.g. when sending in a patch).

The style itself is quite different from what we had before but making it
uniform across all the codebase is the key. I also hope that it'll make the
code more readable (YMMV) and less sensitive to further changes.
2017-04-20 10:01:22 +03:00
Mike Gelfand b82f6009dd Maintain lock file(s) corresponding to session ID 2016-09-27 20:53:10 +03:00
Mike Gelfand 2248d3670f Get rid of $Id$ SVN keywords in source files 2016-09-02 23:10:15 +03:00
Mike Gelfand 3d8c4c3960 Support absolute paths longer than ~260 chars on Windows 2015-10-23 05:29:47 +00:00
Mike Gelfand abb572fe26 Better support for UNC paths in tr_sys_path_is_relative
Accept \\ and // and valid UNC path prefixes, but not \/ or /\.
2015-10-23 03:55:04 +00:00
Mike Gelfand 5f420cafda Rework Win32 basename and dirname implementation
Don't use _splitpath_s and _makepath_s as they don't support long paths
and UNC paths properly. Report error if path is not valid.
2015-10-23 03:42:11 +00:00
Mike Gelfand 650db1f46e #5802: Don't make assumptions of remote path validity in transmission-remote
Defer validity checks until path gets to the remote side, where they
actually make sense. Add simple checks for download directory path to
ensure it's not relative, since one cannot know what current working
directory of the remote process is.
2015-10-20 21:22:19 +00:00
Mike Gelfand 53a0fc2a19 Allow files (and their parent directories) to be renamed even when in use (on Windows). 2015-04-13 18:31:32 +00:00
Mike Gelfand 7bf402bb7d Forward-declare `tr_error` structure in headers 2015-04-11 14:54:01 +00:00
Mike Gelfand cefc477918 Fix a couple more MinGW/MSVC warnings. 2015-03-19 19:13:23 +00:00
Mike Gelfand 9a3b965ce4 Kill some warnings when compiling on Windows 2015-01-02 04:02:13 +00:00
Mike Gelfand 52a9d774e4 Fix compilation on Windows
This should not affect non-Win32 platforms in any way.
As for Win32 (both MinGW and MSVC), this should hopefully allow for
unpatched compilation. Correct functioning is not yet guaranteed though.
2014-12-13 15:22:39 +00:00
Mike Gelfand f6f7bf8227 #4400, #5462: Move random helpers to crypto-utils
On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing random numbers/data generation to crypto-utils.{c,h}. OpenSSL-
related functionality (generation of cryptographically strong random
data) is moved to crypto-utils-openssl.c.

Rename functions to follow currently accepted style:
* tr_cryptoRandBuf -> tr_rand_buffer
* tr_cryptoRandInt -> tr_rand_int
* tr_cryptoWeakRandInt -> tr_rand_int_weak

Fix rare case of invalid value being returned from tr_rand_int. Return
value for abs(INT_MIN) may be undefined and thus negative, and so
tr_rand_int will return negative value which is incorrect (out of
requested and expected range).
2014-12-04 11:27:38 +00:00
Jordan Lee 51a90d0da0 (trunk, libt) #4160 - the slow slog to catch trunk up to mike.dld's 4160 diff continues. This step applies 4160-04a-dir.patch, which adds tr_sys_dir_*() portability wrappers. 2014-09-21 17:52:36 +00:00
Jordan Lee c1beabfea6 (trunk, libT) #4160 'foreign character support' -- merge mike.dld's 4160-03a-file.platch, which introduces tr_sys_file_*() portability wrappers 2014-07-08 00:15:12 +00:00
Jordan Lee 60a5c793d9 (trunk, libT) mike.dld's 4160-02a-path.patch: portability wrapper around file paths. 2014-07-03 21:58:39 +00:00