Skip to content

Commit b30d442

Browse files
authored
Merge branch 'appimagetool/master' into appimagetool/master
2 parents edbb537 + 7fa2236 commit b30d442

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

appimagetool.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ main (int argc, char *argv[])
433433

434434
/* Check if .DirIcon is present in source AppDir */
435435
gchar *diricon_path = g_build_filename(source, ".DirIcon", NULL);
436+
437+
if (! g_file_test(diricon_path, G_FILE_TEST_EXISTS)){
438+
fprintf (stderr, "Deleting pre-existing .DirIcon\n");
439+
g_unlink(diricon_path);
440+
}
436441
if (! g_file_test(diricon_path, G_FILE_TEST_IS_REGULAR)){
437442
fprintf (stderr, "Creating .DirIcon symlink based on information from desktop file\n");
438443
int res = symlink(basename(icon_file_path), diricon_path);

runtime.c

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,47 @@ char* getArg(int argc, char *argv[],char chr)
148148
return NULL;
149149
}
150150

151+
/* mkdir -p implemented in C, needed for https://github.com/probonopd/AppImageKit/issues/333
152+
* https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950 */
153+
int
154+
mkdir_p(const char *path)
155+
{
156+
/* Adapted from http://stackoverflow.com/a/2336245/119527 */
157+
const size_t len = strlen(path);
158+
char _path[PATH_MAX];
159+
char *p;
160+
161+
errno = 0;
162+
163+
/* Copy string so its mutable */
164+
if (len > sizeof(_path)-1) {
165+
errno = ENAMETOOLONG;
166+
return -1;
167+
}
168+
strcpy(_path, path);
169+
170+
/* Iterate the string */
171+
for (p = _path + 1; *p; p++) {
172+
if (*p == '/') {
173+
/* Temporarily truncate */
174+
*p = '\0';
175+
176+
if (mkdir(_path, S_IRWXU) != 0) {
177+
if (errno != EEXIST)
178+
return -1;
179+
}
180+
181+
*p = '/';
182+
}
183+
}
184+
185+
if (mkdir(_path, S_IRWXU) != 0) {
186+
if (errno != EEXIST)
187+
return -1;
188+
}
189+
190+
return 0;
191+
}
151192

152193
int
153194
main (int argc, char *argv[])
@@ -190,8 +231,8 @@ main (int argc, char *argv[])
190231
prefix = "squashfs-root/";
191232

192233
if(access(prefix, F_OK ) == -1 ) {
193-
if (mkdir(prefix, 0777) == -1) {
194-
perror("mkdir error");
234+
if (mkdir_p(prefix) == -1) {
235+
perror("mkdir_p error");
195236
exit(EXIT_FAILURE);
196237
}
197238
}
@@ -218,10 +259,10 @@ main (int argc, char *argv[])
218259
strcat(strcat(prefixed_path_to_extract, prefix), trv.path);
219260
if(inode.base.inode_type == SQUASHFS_DIR_TYPE){
220261
fprintf(stderr, "inode.xtra.dir.parent_inode: %ui\n", inode.xtra.dir.parent_inode);
221-
fprintf(stderr, "mkdir: %s/\n", prefixed_path_to_extract);
262+
fprintf(stderr, "mkdir_p: %s/\n", prefixed_path_to_extract);
222263
if(access(prefixed_path_to_extract, F_OK ) == -1 ) {
223-
if (mkdir(prefixed_path_to_extract, 0777) == -1) {
224-
perror("mkdir error");
264+
if (mkdir_p(prefixed_path_to_extract) == -1) {
265+
perror("mkdir_p error");
225266
exit(EXIT_FAILURE);
226267
}
227268
}

0 commit comments

Comments
 (0)