Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* ssexec_snapshot_remove.c
*
* Copyright (c) 2024 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <unistd.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <oblibs/stack.h>
#include <oblibs/directory.h>
#include <skalibs/sgetopt.h>
#include <66/ssexec.h>
#include <66/constants.h>
int ssexec_snapshot_remove(int argc, char const *const *argv, ssexec_t *info)
{
log_flow() ;
char const *snapname = 0 ;
_alloc_stk_(snapdir, SS_MAX_PATH_LEN) ;
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = subgetopt_r(argc, argv, OPTS_SNAPSHOT_REMOVE, &l) ;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
if (opt == -1) break ;
switch (opt) {
case 'h' :
info_help(info->help, info->usage) ;
return 0 ;
default :
log_usage(info->usage, "\n", info->help) ;
}
}
argc -= l.ind ; argv += l.ind ;
}
if (!argc)
log_usage(info->usage, "\n", info->help) ;
snapname = *argv ;
auto_strings(snapdir.s, info->base.s, SS_SNAPSHOT + 1, "/", snapname) ;
if (access(snapdir.s, F_OK) < 0)
log_dieusys(LOG_EXIT_SYS, "find snapshot: ", snapdir.s) ;
log_trace("delete directory: ", snapdir.s) ;
if (!dir_rm_rf(snapdir.s))
log_dieusys(LOG_EXIT_SYS, "delete snapshot: ", snapdir.s) ;
log_info("Successfully removed snapshot: ", snapname) ;
return 0 ;
}