summaryrefslogtreecommitdiff
path: root/Administrator/inc/private/ssw_pers_admin_files_helper.h
blob: 8b35457c9366d115f60d5e9adc32fec5f487cf31 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifndef SSW_PERS_ADMIN_FILES_HELPER_H
#define SSW_PERS_ADMIN_FILES_HELPER_H

/**********************************************************************************************************************
*
* Copyright (C) 2012 Continental Automotive Systems, Inc.
*
* Author: Ionut.Ieremie@continental-corporation.com
*
* Interface: private - common functionality for files/folder manipulation
*
* The file defines contains the defines according to
* https://collab.genivi.org/wiki/display/genivi/SysInfraEGPersistenceConceptInterface   
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Date       Author    Version  Reason
* 2013.02.07 uidu0250  1.0.0.0	CSP_WZ#1280:  Added persadmin_check_for_same_file_content to check for identical file content
* 2012.11.16 uidv2833  1.0.0.0  CSP_WZ#1280:  persadmin_delete_folder and persadmin_delete_file return the number of bytes deleted
* 2012.11.15 uidl9757  1.0.0.0  CSP_WZ#1280:  Some extensions:
                                - persadmin_copy_folder and persadmin_copy_file return the number of bytes copied
                                - added persadmin_check_if_file_exist and persadmin_check_if_file_exist
* 2012.11.12 uidl9757  1.0.0.0  CSP_WZ#1280:  Created
*
**********************************************************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif  /* #ifdef __cplusplus */

#include "persComTypes.h"
#include "persComDataOrg.h"

#define PERSADMIN_MAX_PATH_LENGHT (PERS_ORG_MAX_LENGTH_PATH_FILENAME + 1) //256
#define PERSADMIN_MAX_NESTING_DEPTH 12

typedef enum
{
    PersadminFilterAll = 0,                 /* all folders and files are selectes */
    PersadminFilterFilesAll,                /* only files are selected (folders are skipped )*/
    PersadminFilterFilesRegular,            /* only regular files are selected (folders and link files are skipped )*/
    PersadminFilterFilesLink,               /* only link files are selected (folders and regular files are skipped )*/
    PersadminFilterFoldersAndRegularFiles,  /* only folders and regular files are selected */
    PersadminFilterFoldersAndLinkFiles,     /* only folders and link files are selected */
    PersadminFilterFolders,                 /* only folders are selected */
}PersadminFilterMode_e ;

/*
* filePath can be absolute or relative
* it is not checked if the file indicated by filePath actually exist
* returns in fileName_out the part of filePath after the last '/' (or the complete filePath if there is no '/') 
*/
sint_t persadmin_get_filename(pstr_t filePath, pstr_t fileName_out, sint_t size);

/*
* filePath can be absolute or relative
* it is not checked if the file indicated by filePath actually exist
* returns the part of filePath after the last '.' (but must be after the last '/') 
*/
sint_t persadmin_get_file_extension(pstr_t filePath, pstr_t fileExtension_out, sint_t size);


/*
* filePath can be absolute or relative
* it is not checked if the file indicated by filePath actually exist
* returns the part of filePath before (and including) the last '/'
*/
sint_t persadmin_get_folder_path(pstr_t filePath, pstr_t folderPath_out, sint_t size);

/*
* check if file/folder indicated by pathname exist
* if (bIsFolder==true) it is checked the existence of the folder, otherway the existence of the file
* returns 0 if the file/folder exist, a negative value other way
*/
sint_t persadmin_check_if_file_exists(pstr_t pathname, bool_t bIsFolder) ;

/*
* create a link in the path indicated by pathLink which points to path indeicated by pathTarget
* there is no check if pathTarget actually exist (or is valid)
* the intermediate folders in pathLink are created if they do not exist
* returns 0 if the file/folder exist, a negative value other way
*/
sint_t persadmin_create_symbolic_link(pstr_t pathLink, pstr_t pathTarget) ;

/**
 * \brief copy the folder indicated by absPathSource into the folder indicated by absPathDestination
 * \usage : persadmin_copy_folder("/Data/mnt-c/App-1/", "/var/Pers/bkup/App_1_bkup/")
 *        : copy the content of /Data/mnt-c/App-1/ into /var/Pers/bkup/App_1_bkup/
 *
 * \param absPathSource         [in] absolute path of source folder
 * \param absPathDestination    [in] absolute path of destination folder
 * \param eFilter               [in]  specify what to list (see PersadminFilterMode_e)
 * \param bRecursive            [in]  if true, a recursive listing is performed
 * \return number of bytes copied, negative value for error
 * TODO: define error codes
 */
sint_t persadmin_copy_folder(pstr_t absPathSource, pstr_t absPathDestination, PersadminFilterMode_e eFilter, bool_t bRecursive);


/**
 * \brief create a folder as indicated by absPath
 * \usage : persadmin_create_folder("/var/Pers/bkup/App_1_bkup/")
 * \note : all the missing folders in the path are created (i.e. /var/Pers/, /var/Pers/bkup/)
 *
 * \param absPath               [in] absolute path to folder to be created
 * \return 0 for success, negative value otherwise;
 * TODO: define error codes
 */
sint_t persadmin_create_folder(pstr_t absPath);

/**
 * \brief delete a folder
 * \usage : persadmin_delete_folder("/var/Pers/bkup/App_1_bkup/")
 *
 * \param absPath               [in] absolute path to folder to be deleted
 * \return positive value: number of bytes deleted; negative value: error
 * TODO: define error codes
 */
sint_t persadmin_delete_folder(pstr_t absPath);

/**
 * \brief copy a file (with posibility to rename the copy)
 * \usage : persadmin_copy_file("/Data/mnt-c/shared/public/cached.itz", "/var/Pers/bkup/CACHED.itz")
 *        : content of /Data/mnt-c/shared/public/cached.itz is copied into /var/Pers/bkup/CACHED.itz
 *
 * \param absPathSource         [in] absolute path to the source file
 * \param absPathDestination    [in] absolute path to the destination file
 * \return number of bytes copied, negative value for error
 * TODO: define error codes
 */
sint_t persadmin_copy_file(pstr_t absPathSource, pstr_t absPathDestination);

/**
 * \brief delete a file
 * \usage : persadmin_delete_file("/Data/mnt-c/shared/public/cached.itz")
 *
 * \param absPath               [in] absolute path to the file to be deleted
 * \return positive value: number of bytes deleted; negative value: error
 * TODO: define error codes
 */
sint_t persadmin_delete_file(pstr_t absPath);

/**
 * \brief list the content of a folder
 *
 * \param folderPath            [in]  absolute path to the folder to be listed
 * \param buffer_out            [out] where the listing is save ; entries are relative to folderPath and separated by '\0'
 * \param bufSize               [in]  size of buffer_out
 * \param eFilter               [in]  specify what to list (see PersadminFilterMode_e)
 * \param bRecursive            [in]  if true, a recursive listing is performed
 * \return positive value - the size of data passed in buffer_out, negative - error;
 * TODO: define error codes
 */
sint_t persadmin_list_folder(pconststr_t folderPath, pstr_t buffer_out, sint_t bufSize, PersadminFilterMode_e eFilter, bool_t bRecursive) ;

/**
 * \brief find the buffer size needed to accommodate the output of a list folder request
 *
 * \param folderPath        [in]  absolute path to the folder to be listed
 * \param eListingMode      [in]  specify what to list (see PersadminFilterMode_e)
 * \param bRecursive        [in]  if true, a recursive listing is performed
 * \return positive value - the size needed, negative - error;
 * TODO: define error codes
 */
sint_t persadmin_list_folder_get_size(pconststr_t folderPath, PersadminFilterMode_e eListingMode, bool_t bRecursive) ;

/**
 * \brief Computes the size in bytes of all files located under the specified folder path. The file search is done recursively.
 *
 * \param folderPath        [in]  absolute path to the folder to be queried
 * \return positive value - the size in bytes of all files, negative - error;
 * TODO: define error codes
 */
sint_t persadmin_get_folder_size( pconststr_t folderPath );

/**
 * \brief Checks if the files specified have identical contents (without the usage of checksums)
 *
 * \param file1Path        [in]  absolute path to one of the files to be checked
 * \param file2Path		   [in]  absolute path to the other file to be checked
 * \return true - if the files have identical contents, false - otherwise;
 */
bool_t persadmin_check_for_same_file_content(pstr_t file1Path, pstr_t file2Path);

#ifdef __cplusplus
}
#endif /* extern "C" { */

#endif /*SSW_PERS_ADMIN_FILES_HELPER_H */