source: rtems/testsuites/libtests/tar01/init.c @ d84e346

Last change on this file since d84e346 was d84e346, checked in by Chris Johns <chrisj@…>, on May 18, 2016 at 11:18:21 PM

libmisc/untar: Support directory create and overwrites. Share the common code.

Support creating directories for files with a path depth greater than 1. Some
tar files can have files with a path depth greater than 1 and no directory
entry in the tar file to create a directory.

Support overwriting existing files and directories failing in a similar
way to tar on common hosts. If a file is replaced with a file delete the
file and create a new file. If a directory replaces a file remove the file
and create the directory. If a file replaces a directory remove the directory,
and if the directory is not empty and cannot be removed report an error. If a
directory alreday exists do nothing leaving the contents untouched.

The untar code now shares the common header parsing and initial processing
with the actual writes still separate. No changes to the IMFS have been made.

Updates #2415.
Closes #2207.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <bsp.h> /* for device driver prototypes */
15#include "tmacros.h"
16#include <rtems/untar.h>
17#include <rtems/error.h>
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <fcntl.h>
24#include <unistd.h>
25
26#include "initial_filesystem_tar.h"
27
28const char rtems_test_name[] = "TAR 1";
29
30/* forward declarations to avoid warnings */
31rtems_task Init(rtems_task_argument argument);
32void test_untar_from_memory(void);
33void test_untar_from_file(void);
34
35#define TARFILE_START initial_filesystem_tar
36#define TARFILE_SIZE  initial_filesystem_tar_size
37
38void test_cat(
39  char *file,
40  int   offset_arg,
41  int   length
42);
43
44void test_untar_from_memory(void)
45{
46  rtems_status_code sc;
47  rtems_printer     printer;
48
49  rtems_print_printer_printf(&printer);
50
51  printf("Untaring from memory - ");
52  sc = Untar_FromMemory_Print((void *)TARFILE_START, TARFILE_SIZE, &printer);
53  if (sc != RTEMS_SUCCESSFUL) {
54    printf ("error: untar failed: %s\n", rtems_status_text (sc));
55    exit(1);
56  }
57  printf ("successful\n");
58
59  /******************/
60  printf( "========= /home/test_file =========\n" );
61  test_cat( "/home/test_file", 0, 0 );
62
63  /******************/
64  printf( "========= /symlink =========\n" );
65  test_cat( "/symlink", 0, 0 );
66
67}
68
69void test_untar_from_file(void)
70{
71  int                fd;
72  int                rv;
73  ssize_t            n;
74
75  puts( "Copy tar image to test.tar" );
76  /* Copy tar image from object to file in IMFS */
77  fd = open( "/test.tar", O_CREAT|O_TRUNC|O_WRONLY, 0777 );
78  rtems_test_assert( fd != -1 );
79
80  n = write( fd, TARFILE_START, TARFILE_SIZE );
81  rtems_test_assert( n == TARFILE_SIZE );
82  close( fd );
83
84  /* make a directory to untar it into */
85  rv = mkdir( "/dest", 0777 );
86  rtems_test_assert( rv == 0 );
87
88  rv = chdir( "/dest" );
89  rtems_test_assert( rv == 0 );
90
91  /* Untar it */
92  rv = Untar_FromFile( "/test.tar" );
93  printf("Untaring from file - ");
94  if (rv != UNTAR_SUCCESSFUL) {
95    printf ("error: untar failed: %i\n", rv);
96    exit(1);
97  }
98  printf ("successful\n");
99
100  /******************/
101  printf( "========= /dest/home/test_file =========\n" );
102  test_cat( "/dest/home/test_file", 0, 0 );
103
104  /******************/
105  printf( "========= /dest/symlink =========\n" );
106  test_cat( "/dest/symlink", 0, 0 );
107}
108
109rtems_task Init(
110  rtems_task_argument ignored
111)
112{
113  TEST_BEGIN();
114
115  test_untar_from_memory();
116  puts( "" );
117  test_untar_from_file();
118
119  TEST_END();
120  exit( 0 );
121}
122
123
124/* NOTICE: the clock driver is explicitly disabled */
125#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
126#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
127
128#define CONFIGURE_MAXIMUM_TASKS            1
129#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
130
131#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
132
133#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
134
135#define CONFIGURE_INIT
136#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.