Files
electronics-inventory/tools/mv-sync.c
mikael-lovqvists-claude-agent 58c93f2bd0 Many UX and correctness improvements
- Components URL reflects selected component (/components/:id), survives refresh
- Word-split search: "0603 res" matches "Resistor 0603"
- Left pane resizable with localStorage persistence
- Field values rendered via central render_field_value() (units, URLs, extensible)
- Fields sorted alphabetically in both detail view and edit dialog
- Edit component dialog widened; field rows use shared grid columns (table-like)
- No space between value and unit (supports prefix suffixes like k, M, µ)
- Grid viewer highlights and scrolls to cell when navigating from component detail
- Cell inventory overlay items are <a> tags — middle-click opens in new tab
- PDF files stored with sanitized human-readable filename, not random ID
- PDF rename also renames file on disk
- Atomic rename via renameat2(RENAME_NOREPLACE) through tools/mv-sync
- Fix .cell-thumb-link → .cell-thumb-preview (div, not anchor), cursor: zoom-in
- Fix field name overflow in detail view (auto column width, overflow-wrap)
- Fix link color: use --accent instead of browser default dark blue

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 02:49:11 +00:00

43 lines
824 B
C

/*
* mv-sync: atomic rename that fails if the destination already exists.
*
* Uses renameat2(2) with RENAME_NOREPLACE (Linux 3.15+).
*
* Exit codes:
* 0 success
* 1 rename failed (reason on stderr)
* 2 wrong number of arguments
*/
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#ifndef RENAME_NOREPLACE
#define RENAME_NOREPLACE (1 << 0)
#endif
int main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr, "usage: mv-sync <src> <dst>\n");
return 2;
}
long ret = syscall(SYS_renameat2,
AT_FDCWD, argv[1],
AT_FDCWD, argv[2],
RENAME_NOREPLACE);
if (ret != 0) {
fprintf(stderr, "mv-sync: rename \"%s\" -> \"%s\": %s\n",
argv[1], argv[2], strerror(errno));
return 1;
}
return 0;
}