Changeset 0ce9eb8 in mainline for uspace/app/copy/copy.c


Ignore:
Timestamp:
2026-02-10T12:52:07Z (8 days ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
857fba8
Parents:
26a9388
git-author:
Jiri Svoboda <jiri@…> (2026-02-10 18:51:59)
git-committer:
Jiri Svoboda <jiri@…> (2026-02-10 12:52:07)
Message:

Ask user what to do if destination file exists while copying.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/copy/copy.c

    r26a9388 r0ce9eb8  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4949static void copy_progress(void *, fmgt_progress_t *);
    5050static fmgt_error_action_t copy_io_error_query(void *, fmgt_io_error_t *);
     51static fmgt_exists_action_t copy_exists_query(void *, fmgt_exists_t *);
    5152
    5253static bool prog_upd = false;
     
    5960        .abort_query = copy_abort_query,
    6061        .io_error_query = copy_io_error_query,
     62        .exists_query = copy_exists_query,
    6163        .progress = copy_progress,
    6264};
     
    188190                                if (ev->key == KC_C)
    189191                                        return fmgt_er_abort;
     192                        }
     193                }
     194        }
     195}
     196
     197/** Called by fmgt to let user choose destination exists recovery action.
     198 *
     199 * @param arg Argument (not used)
     200 * @param err I/O error report
     201 * @return Error recovery action.
     202 */
     203static fmgt_exists_action_t copy_exists_query(void *arg, fmgt_exists_t *exists)
     204{
     205        cons_event_t event;
     206        kbd_event_t *ev;
     207        errno_t rc;
     208
     209        (void)arg;
     210
     211        if (nonint)
     212                return fmgt_exr_abort;
     213
     214        if (prog_upd)
     215                putchar('\n');
     216
     217        fprintf(stderr, "File %s exists.\n", exists->fname);
     218        fprintf(stderr, "[O]verwrite, [S]kip or [A]bort?\n");
     219
     220        if (con == NULL)
     221                return fmgt_exr_abort;
     222
     223        while (true) {
     224                rc = console_get_event(con, &event);
     225                if (rc != EOK)
     226                        return fmgt_exr_abort;
     227
     228                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) {
     229                        ev = &event.ev.key;
     230                        if ((ev->mods & KM_ALT) == 0 &&
     231                            (ev->mods & KM_CTRL) == 0) {
     232                                if (ev->c == 'o' || ev->c == 'O')
     233                                        return fmgt_exr_overwrite;
     234                                if (ev->c == 's' || ev->c == 'S')
     235                                        return fmgt_exr_skip;
     236                                if (ev->c == 'a' || ev->c == 'A')
     237                                        return fmgt_exr_abort;
     238                        }
     239                }
     240
     241                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) {
     242                        ev = &event.ev.key;
     243                        if ((ev->mods & KM_ALT) == 0 &&
     244                            (ev->mods & KM_SHIFT) == 0 &&
     245                            (ev->mods & KM_CTRL) != 0) {
     246                                if (ev->key == KC_C)
     247                                        return fmgt_exr_abort;
    190248                        }
    191249                }
     
    256314                putchar('\n');
    257315        if (rc != EOK) {
    258                 printf("Error creating file: %s.\n", str_error(rc));
     316                printf("Error copying file(s): %s.\n", str_error(rc));
    259317                goto error;
    260318        }
Note: See TracChangeset for help on using the changeset viewer.