File: prepare.c

package info (click to toggle)
cdebootstrap 0.3.4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 816 kB
  • ctags: 308
  • sloc: sh: 3,408; ansic: 2,522; makefile: 243
file content (79 lines) | stat: -rw-r--r-- 2,125 bytes parent folder | download
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
/*
 * prepare.c
 *
 * Copyright (C) 2003 Bastian Blank <waldi@debian.org>
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * $LastChangedBy: bastian $
 * $LastChangedDate: 2005-01-05 22:48:37 +0100 (Mi, 05 Jan 2005) $
 * $LastChangedRevision: 785 $
 */

#include <config.h>

#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "execute.h"
#include "install.h"
#include "prepare.h"

int prepare_download (void)
{
  int ret = 0;
  ret |= prepare_dir ("/var/cache/apt/archives");
  ret |= prepare_dir ("/var/lib/apt/lists");
  return ret != 0;
}

int prepare_install (void)
{
  int ret = 0;
  ret |= prepare_dir ("/var/lib/dpkg");
  ret |= prepare_file ("/var/lib/dpkg/available");
  ret |= prepare_file ("/var/lib/dpkg/diversions");
  ret |= prepare_file ("/var/lib/dpkg/status");
  ret |= prepare_dir ("/var/log");
  return ret != 0;
}

int prepare_dir (const char *dir)
{
  char buf[PATH_MAX];
  struct stat statbuf;
  snprintf (buf, sizeof (buf), "%s/%s", install_root, dir);
  if (!stat (buf, &statbuf))
    return 0;
  snprintf (buf, sizeof (buf), "mkdir -p %s/%s", install_root, dir);
  return execute (buf);
}

int prepare_file (const char *file)
{
  char buf[PATH_MAX];
  int fd;
  snprintf (buf, sizeof (buf), "%s/%s", install_root, file);
  fd = open (buf, O_WRONLY | O_CREAT | O_TRUNC);
  if (fd < 0)
    return 1;
  close (fd);
  return 0;
}