aboutsummaryrefslogtreecommitdiff
path: root/src/vtab.c
blob: e05b9647193ff4c5c48bf1d58f9c6f3492283ec7 (plain)
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
39
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* wydawca - automatic release submission daemon
   Copyright (C) 2009-2011 Sergey Poznyakoff

   Wydawca is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3 of the License, or (at your
   option) any later version.

   Wydawca is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with wydawca. If not, see <http://www.gnu.org/licenses/>. */

#include "wydawca.h"

struct virt_tab_reg
{
  char *scheme;
  struct virt_tab vtab;
};

static struct virt_tab_reg reg[] = {
  { "file",
    { dir_test_url, dir_move_file, dir_archive_file,
      dir_symlink_file, dir_rmsymlink_file } },
  { "dir",
    { dir_test_url, dir_move_file, dir_archive_file,
      dir_symlink_file, dir_rmsymlink_file } },
  { "null",
    { NULL, null_move_file, null_archive_file, null_symlink_file,
      null_rmsymlink_file } },
  { NULL }
};

int
url_to_vtab (mu_url_t url, struct virt_tab *vtab)
{
  const char *scheme;
  int i;

  if (mu_url_sget_scheme (url, &scheme))
    return 1;
  for (i = 0; reg[i].scheme; i++)
    if (strcmp (reg[i].scheme, scheme) == 0)
      {
	*vtab = reg[i].vtab;
	return 0;
      }
  return 1;
}


int
move_file (struct file_triplet *trp, enum file_type file_id)
{
  int rc = trp->spool->vtab.move_file (trp, file_id);
  report_add ("Move %s to %s: %s", trp->file[file_id].name, trp->relative_dir,
	      rc == 0 ? "OK" : "FAILED");
  return rc;
}

int
archive_file (struct file_triplet *trp, const char *file_name)
{
  int rc = trp->spool->vtab.archive_file (trp, file_name);
  report_add ("Archive and remove %s/%s: %s", trp->relative_dir, file_name,
	      rc == 0 ? "OK" : "FAILED");
  return rc;
}

int
symlink_file (struct file_triplet *trp,
	      const char *wanted_src, const char *wanted_dst)
{
  int rc = trp->spool->vtab.symlink_file (trp, wanted_src, wanted_dst);
  report_add ("Symlink %s to %s in %s/: %s", wanted_src, wanted_dst,
	      trp->relative_dir,
	      rc == 0 ? "OK" : "FAILED");
  return rc;
}

int
rmsymlink_file (struct file_triplet *trp, const char *file_name)
{
  int rc = trp->spool->vtab.rmsymlink_file (trp, file_name);
  report_add ("Remove symlink %s/%s: %s", trp->relative_dir, file_name,
	      rc == 0 ? "OK" : "FAILED");
  return rc;
}

Return to:

Send suggestions and report system problems to the System administrator.