*перезапись тэгов сохраняет владельца и права исходного файла (файлы библиотеки на NAS)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d85b105d1c
commit
1e686ba304
2 files changed
+27
No files matched your search
@@ -564,6 +564,9 @@ fn write_book_tags_impl(path string, t BookTags, opts WriteOptions) ! {
|
|||||||
parsed := parse_id3v2(path)!
|
parsed := parse_id3v2(path)!
|
||||||
tag := build_tag(parsed, t, opts)
|
tag := build_tag(parsed, t, opts)
|
||||||
|
|
||||||
|
// Владелец и права исходного файла: перезапись через временный файл иначе их потеряет
|
||||||
|
// (на NAS файлы библиотеки принадлежат пользователю приложения, а агент может работать от root)
|
||||||
|
orig := os.stat(path) or { os.Stat{} }
|
||||||
tmp_path := path + '.tagtmp'
|
tmp_path := path + '.tagtmp'
|
||||||
mut src := os.open(path)!
|
mut src := os.open(path)!
|
||||||
mut dst := os.create(tmp_path)!
|
mut dst := os.create(tmp_path)!
|
||||||
@@ -589,6 +592,12 @@ fn write_book_tags_impl(path string, t BookTags, opts WriteOptions) ! {
|
|||||||
src.close()
|
src.close()
|
||||||
dst.close()
|
dst.close()
|
||||||
ok = true
|
ok = true
|
||||||
|
if orig.mode != 0 {
|
||||||
|
os.chmod(tmp_path, int(orig.mode & 0o7777)) or {}
|
||||||
|
$if !windows {
|
||||||
|
os.chown(tmp_path, int(orig.uid), int(orig.gid)) or {}
|
||||||
|
}
|
||||||
|
}
|
||||||
os.mv(tmp_path, path, overwrite: true)!
|
os.mv(tmp_path, path, overwrite: true)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,3 +113,21 @@ fn test_broken_tag_is_error() {
|
|||||||
}
|
}
|
||||||
assert false, 'ошибка не возвращена'
|
assert false, 'ошибка не возвращена'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Права файла сохраняются после перезаписи
|
||||||
|
fn test_write_keeps_mode() {
|
||||||
|
path := tmp_copy('test_id3v23.mp3')
|
||||||
|
defer {
|
||||||
|
os.rm(path) or {}
|
||||||
|
}
|
||||||
|
$if !windows {
|
||||||
|
os.chmod(path, 0o640) or { panic(err) }
|
||||||
|
}
|
||||||
|
before := os.stat(path) or { panic(err) }
|
||||||
|
metadata.write_book_tags(path, metadata.BookTags{
|
||||||
|
title: 'Права'
|
||||||
|
}) or { panic(err) }
|
||||||
|
after := os.stat(path) or { panic(err) }
|
||||||
|
assert after.mode & 0o777 == before.mode & 0o777
|
||||||
|
assert after.uid == before.uid
|
||||||
|
}
|
||||||
Reference in new issue
Block a user