Windowsμ κ²½μ°, tr_sys_path_rename
νλκ·Έλ₯Ό μ¬μ©ν μ MOVEFILE_COPY_ALLOWED
κ·Έκ²μ보λ€λ μμ μ λ΄μ₯μ "μ½κΈ° λ° λ³΅μ¬"μμ 루νλ₯Ό util.c:tr_moveFile
κ·Έλ° λ€μ Linux λ²μ μ κ°κ°μ λ°λ³΅νλ λμ λ νλμ μΈ copy_file_range
λ₯Ό μ¬μ©ν μ μμ΅λλ€.
μλ§λ λ€μκ³Ό κ°μ΅λλ€.
size_t tr_sys_file_copy(tr_sys_file_t infile, tr_sys_file_t outfile, size_t len, tr_error** error )
{
TR_ASSERT(outfile != NULL);
TR_ASSERT(infile != NULL);
bool ret = false;
unsigned int flags = 0;
size_t res;
res = copy_file_range(infile, NULL, outfile, NULL, &len, flags);
if (res) {
return res;
}
else {
set_system_error(error, errno);
return res;
}
}
κ·Έλ¦¬κ³ μλ§λ:
tr_sys_file_copy_fallback(tr_sys_file_t infile, tr_sys_file_t outfile, size_t len, tr_error** error ) {
TR_ASSERT(outfile != NULL);
TR_ASSERT(infile != NULL);
uint64_t bytesLeft = len;
size_t const buflen = 1024 * 128; /* 128 KiB buffer */
tr_sys_path_info info;
while (bytesLeft > 0)
{
uint64_t const bytesThisPass = MIN(bytesLeft, buflen);
uint64_t numRead;
uint64_t bytesWritten;
if (!tr_sys_file_read(infile, buf, bytesThisPass, &numRead, error))
{
break;
}
if (!tr_sys_file_write(outfile, buf, numRead, &bytesWritten, error))
{
break;
}
TR_ASSERT(numRead == bytesWritten);
TR_ASSERT(bytesWritten <= bytesLeft);
bytesLeft -= bytesWritten;
}
return bytesLeft;
}
κ·Έλ° λ€μ Linux λ²μ μ κ°κ°μ λ°λ³΅νλ λμ μ΅μ copy_file_rangeλ₯Ό μ¬μ©ν μ μμ΅λλ€.
μ΄κ²μ ν λ²μ νΈμΆλ‘(λλ κ°λ¨ν 루νμμ) μνν μ μμ΅λλ€.
If file_in is a sparse file, then copy_file_range() may expand any
holes existing in the requested range. Users may benefit from calling
copy_file_range() in a loop, and using the lseek(2) SEEK_DATA and
SEEK_HOLE operations to find the locations of data segments.
(λ¨μ copy_file_range)
μ΄μμ μΌλ‘λ μ μ ν μ κΈμ 보μ₯νκ³ λ³λμ μ€λ λμμ sendfile()μ μ¬μ©ν΄μΌ ν©λλ€.
μ΄λ νμ¬ "νμΌ μ΄λ" μ½λμ κ±°μ λμΌν©λλ€.
rename
μ€ν¨. ν¬μ μΉμ
λ μ μ§νμ§ μμΌλ―λ‘
κ·Έκ²μ κ΅μ²΄ν λ λ¬Έμ λ₯Ό κ³ λ €νμμμ€.
2019λ
7μ 14μΌ μΌμμΌ μ€ν 10μ 41λΆ andreygursky [email protected]μ΄ λ€μκ³Ό κ°μ΄ μΌμ΅λλ€.
>
κ·Έλ° λ€μ Linux λ²μ μ κ°κ°μ λ°λ³΅νλ λμ μ΅μ copy_file_rangeλ₯Ό μ¬μ©ν μ μμ΅λλ€.
μ΄κ²μ ν λ²μ νΈμΆλ‘(λλ κ°λ¨ν 루νμμ) μνν μ μμ΅λλ€.
If file_in is a sparse file, then copy_file_range() may expand any holes existing in the requested range. Users may benefit from calling copy_file_range() in a loop, and using the lseek(2) SEEK_DATA and SEEK_HOLE operations to find the locations of data segments.
(λ¨μ copy_file_range)
μ΄μμ μΌλ‘λ μ μ ν μ κΈμ 보μ₯νκ³ λ³λμ μ€λ λμμ sendfile()μ μ¬μ©ν΄μΌ ν©λλ€.
β
μ€λ λλ₯Ό μμ±νκΈ° λλ¬Έμ μ΄ λ©μμ§λ₯Ό λ°λ κ²μ λλ€.
μ΄ μ΄λ©μΌμ μ§μ λ΅μ₯νκ±°λ GitHubμμ 보거λ μ€λ λλ₯Ό μμκ±°νμΈμ.
μ°Έμ‘°λ‘ λ§ν¬λ νμ¬ "νμΌ μ΄λ"
νμ¬ κΈ°λ₯:
https://github.com/transmission/transmission/blob/master/libtransmission/utils.c#L1682
https://github.com/transmission/transmission/blob/master/libtransmission/utils.c#L1744
ν¬μ μΉμ λ μ μ§νμ§ μμΌλ―λ‘
κ·Έκ²μ κ΅μ²΄ν λ λ¬Έμ λ₯Ό κ³ λ €νμμμ€.
κ·Έλ¦¬κ³ μΌλ° νμΌμ λν μ¬μ ν λΉμ΄ λλ½λμμ΅λλ€.
μ. κ·Έκ²λ. "νμΌ μ΄λ"μ νμ¬ μλͺ»λ λμμ μΌλΆ μ€μ μμ ν°λ¬΄λμλ λ‘λλ₯Ό μΌκΈ°νκΈ°μ μΆ©λΆν©λλ€. κ°λ₯νλ€λ©΄ glibc copy_file_rangeμ ν΄λ°± μ루μ λ λ λμ ꡬνμΈ κ² κ°μ΅λλ€.
μ΄κ±° κ°μ§κ³ λμμ΄. ν¬λ‘μ€ νλ«νΌ λ°©μμΌλ‘ μ¬λ°λ₯Έ μμ μ μννλ κ²μ μ΄λ ΅μ΅λλ€. 컀λ λ΄ λ³΅μ¬λ₯Ό μν POSIX μΈν°νμ΄μ€κ° μλ κ² κ°μ΅λλ€. κ·Έλ¬λ νμΌ μμ€ν μ΄ λ³΅μ¬λ³Έμ ν¨μ¨μ±μ λμ¬κ°μ λ°λΌ ν΄λΉ κΈ°λ₯μ μλμΌλ‘ μ‘μΈμ€νκΈ°λ₯Ό μνκΈ° λλ¬Έμ κ° μ΄μ 체μ μ λν΄ νΉλ³ν λμλ¬Έμλ₯Ό ꡬλΆν κ°μΉκ° μλ€κ³ μκ°ν©λλ€.
MacOSX λ° FreeBSDμμ κΈ°λ³Έ ꡬνμ μ€ννκ³ μμ§λ§ ν μ€νΈν μμ€ν μ λͺ κ° λ μ€μ ν΄μΌ ν©λλ€.
μ΄ μμ μ νμΌμ λΉλκΈ°μμΌλ‘ μ΄λνλ κ²κ³Ό μ§κ΅νλ€κ³ μκ°ν©λλ€. νμͺ½μ΄ λ€λ₯Έ μͺ½μ λ°©ν΄ν΄μλ μ λ©λλ€. μμ λ΄μ¬ νλ‘μ νΈμ κ²½μ° λ²μ μ΄λμ μμ°μ±μ μ μ λλ€.
λ³κ²½ μ¬νμ λ€μκ³Ό κ°μ΅λλ€. https://github.com/transmission/transmission/compare/master...RobCrowston :kernelcopy-wip
κ°λ¨ν λ§ν΄μ tr_sys_path_copy()λΌλ μλ‘μ΄ μΆμνλ₯Ό λ§λλλ€. (μ΄λ₯Ό λΉλκΈ° μμ μΌλ‘ λ§λ€ λ λ€λ₯Έ μ€λ λμ νμΌ νΈλ€μ λ«κΈ° μν΄ λ³΅μ¬κ° μλ£λ ν λΆνμ€ν κΈ°κ° λμ μλ³Έ νμΌμ μ μ§ν΄μΌ ν μλ μκΈ° λλ¬Έμ μ΄λ λμ 볡μ¬λ³Έμ μ¬μ©νμ΅λλ€.)
μ€λ μ§κΈκΉμ§ MacOS 10.15.1, Windows Server 2016, Linux 5.0(Ubuntu 19.05), Linux 5.3(Arch 2019-12-03), FreeBSD 12.1μμ μλ‘μ΄ ν μ€νΈ(transmission-test-copy)λ₯Ό μ»΄νμΌνκ³ μ€ννμ΅λλ€. (userspace fallback μ¬μ©), FreeBSD 13. κ°κ°μ κ²½μ°μ μ μ ν μμ€ν νΈμΆμ νκ³ μμμ λλ²κ±°λ‘ νμΈνμ΅λλ€. λΆννκ²λ κ΄λ ¨ μλ λͺ κ°μ§ libevent λ¬Έμ λλ¬Έμ OpenBSD 6.5, NetBSD 8.1 λλ Solaris 10μμ λΉλν μ½λλ₯Ό μ»μ μ μμμ΅λλ€. μ΄λ€ κ²½μ°μλ μ΄ λ³κ²½ μ¬νμ ν΄λΉ νλ«νΌμ μν₯μ λ―ΈμΉμ§ μμμΌ ν©λλ€.
μμ§ ν μΌ:
νΌλλ°± νμν©λλ€.
λ°μ΄ν°λ₯Ό λΉλκΈ°μμΌλ‘ μ΄λνλ €λ©΄ +1μ λλ€. νμΌ μμ€ν κ°μ λμ©λ ν λ νΈλ₯Ό μ΄λ νλ©΄ μ 체 μμ© νλ‘κ·Έλ¨μ΄ μ κΉλλ€ .
κ°μ₯ μ μ©ν λκΈ
λ°μ΄ν°λ₯Ό λΉλκΈ°μμΌλ‘ μ΄λνλ €λ©΄ +1μ λλ€. νμΌ μμ€ν κ°μ λμ©λ ν λ νΈλ₯Ό μ΄λ νλ©΄ μ 체 μμ© νλ‘κ·Έλ¨μ΄ μ κΉλλ€ .