2005-06-21 18:17:51 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2006-04-22 03:50:36 +04:00
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2005-06-21 18:17:51 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Provides a central method of obtaining unique filenames.
|
|
|
|
*
|
|
|
|
* A maximum of 2^24 files can be allocated at any point in time.
|
|
|
|
*/
|
|
|
|
|
2006-04-22 03:50:36 +04:00
|
|
|
#include <dirent.h>
|
2005-06-21 18:17:51 +04:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2006-04-22 03:50:36 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "netsurf/utils/filename.h"
|
2005-06-21 18:17:51 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
2006-06-21 02:58:36 +04:00
|
|
|
#include "netsurf/utils/utils.h"
|
2005-06-21 18:17:51 +04:00
|
|
|
|
|
|
|
#define FULL_WORD (unsigned int)4294967295
|
2006-01-02 02:54:02 +03:00
|
|
|
/* '0' + '0' * 10 */
|
2006-01-06 23:56:44 +03:00
|
|
|
#define START_PREFIX 528
|
2005-06-21 18:17:51 +04:00
|
|
|
|
|
|
|
struct directory {
|
2006-01-06 23:56:44 +03:00
|
|
|
int numeric_prefix; /** numeric representation of prefix */
|
2006-04-22 03:50:36 +04:00
|
|
|
char prefix[10]; /** directory prefix, eg '00/11/52/' */
|
2006-01-06 23:56:44 +03:00
|
|
|
unsigned int low_used; /** first 32 files, 1 bit per file */
|
|
|
|
unsigned int high_used; /** last 32 files, 1 bit per file */
|
2005-06-21 18:17:51 +04:00
|
|
|
struct directory *next; /** next directory (sorted by prefix) */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct directory *root = NULL;
|
2006-04-22 03:50:36 +04:00
|
|
|
static char filename_buffer[12];
|
|
|
|
static char filename_directory[256];
|
2005-06-21 18:17:51 +04:00
|
|
|
|
2006-04-22 03:50:36 +04:00
|
|
|
static struct directory *filename_create_directory(const char *prefix);
|
|
|
|
static bool filename_flush_directory(const char *folder, int depth);
|
|
|
|
static bool filename_delete_recursive(char *folder);
|
2005-06-21 18:17:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a new, unique, filename.
|
|
|
|
*
|
2006-06-21 02:58:36 +04:00
|
|
|
* \return a pointer to a shared buffer containing the new filename or NULL on failure
|
2005-06-21 18:17:51 +04:00
|
|
|
*/
|
2006-06-21 02:58:36 +04:00
|
|
|
const char *filename_request(void) {
|
2005-06-21 18:17:51 +04:00
|
|
|
struct directory *dir;
|
|
|
|
int i = -1;
|
2006-01-06 23:56:44 +03:00
|
|
|
|
2005-06-21 18:17:51 +04:00
|
|
|
for (dir = root; dir; dir = dir->next)
|
|
|
|
if ((dir->low_used & dir->high_used) != FULL_WORD) {
|
2006-01-06 23:56:44 +03:00
|
|
|
if (dir->low_used != FULL_WORD) {
|
2005-06-21 18:17:51 +04:00
|
|
|
for (i = 0; (dir->low_used & (1 << i)); i++);
|
2006-01-06 23:56:44 +03:00
|
|
|
} else {
|
2005-06-21 18:17:51 +04:00
|
|
|
for (i = 0; (dir->high_used & (1 << i)); i++);
|
2006-01-06 23:56:44 +03:00
|
|
|
i += 32;
|
|
|
|
}
|
2005-06-21 18:17:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == -1) {
|
|
|
|
/* no available slots - create a new directory */
|
2006-04-22 03:50:36 +04:00
|
|
|
dir = filename_create_directory(NULL);
|
2005-06-21 18:17:51 +04:00
|
|
|
if (!dir) {
|
|
|
|
LOG(("Failed to create a new directory."));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
i = 63;
|
|
|
|
}
|
2005-06-23 21:17:56 +04:00
|
|
|
if (i < 32)
|
2005-06-21 18:17:51 +04:00
|
|
|
dir->low_used |= (1 << i);
|
2005-06-23 21:17:56 +04:00
|
|
|
else
|
2005-06-21 18:17:51 +04:00
|
|
|
dir->high_used |= (1 << (i - 32));
|
2006-04-22 03:50:36 +04:00
|
|
|
sprintf(filename_buffer, "%s%.2i", dir->prefix, i);
|
|
|
|
return filename_buffer;
|
2005-06-21 18:17:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-23 21:17:56 +04:00
|
|
|
/**
|
|
|
|
* Claim a specific filename.
|
|
|
|
*
|
|
|
|
* \param filename the filename to claim
|
|
|
|
* \return whether the claim was successful
|
|
|
|
*/
|
2006-04-22 03:50:36 +04:00
|
|
|
bool filename_claim(const char *filename) {
|
2006-01-02 02:54:02 +03:00
|
|
|
char dir_prefix[9];
|
|
|
|
int file;
|
2005-06-23 21:17:56 +04:00
|
|
|
struct directory *dir;
|
2006-01-06 23:56:44 +03:00
|
|
|
|
2006-04-22 03:50:36 +04:00
|
|
|
/* filename format is always '01/23/45/XX' */
|
2006-01-03 01:15:28 +03:00
|
|
|
strncpy(dir_prefix, filename, 9);
|
2006-01-02 02:54:02 +03:00
|
|
|
dir_prefix[9] = '\0';
|
|
|
|
file = (filename[10] + filename[9] * 10 - START_PREFIX);
|
2006-01-06 23:56:44 +03:00
|
|
|
|
2005-06-23 21:17:56 +04:00
|
|
|
/* create the directory */
|
2006-04-22 03:50:36 +04:00
|
|
|
dir = filename_create_directory(dir_prefix);
|
2005-06-23 21:17:56 +04:00
|
|
|
if (!dir)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* update the entry */
|
2006-01-06 23:56:44 +03:00
|
|
|
if (file < 32) {
|
|
|
|
if (dir->low_used & (1 << file))
|
|
|
|
return false;
|
|
|
|
dir->low_used |= (1 << file);
|
|
|
|
} else {
|
|
|
|
if (dir->high_used & (1 << (file - 32)))
|
|
|
|
return false;
|
|
|
|
dir->high_used |= (1 << (file - 32));
|
|
|
|
}
|
|
|
|
return true;
|
2005-06-23 21:17:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-21 18:17:51 +04:00
|
|
|
/**
|
|
|
|
* Releases a filename for future use.
|
|
|
|
*
|
|
|
|
* \param filename the filename to release
|
|
|
|
*/
|
2006-04-22 03:50:36 +04:00
|
|
|
void filename_release(const char *filename) {
|
2005-06-21 18:17:51 +04:00
|
|
|
struct directory *dir;
|
2006-01-02 02:54:02 +03:00
|
|
|
int index, file;
|
|
|
|
|
2006-04-22 03:50:36 +04:00
|
|
|
/* filename format is always '01/23/45/XX' */
|
2006-01-02 02:54:02 +03:00
|
|
|
index = ((filename[7] + filename[6] * 10 - START_PREFIX) |
|
|
|
|
((filename[4] + filename[3] * 10 - START_PREFIX) << 6) |
|
|
|
|
((filename[1] + filename[0] * 10 - START_PREFIX) << 12));
|
|
|
|
file = (filename[10] + filename[9] * 10 - START_PREFIX);
|
2006-01-06 23:56:44 +03:00
|
|
|
|
2005-06-21 18:17:51 +04:00
|
|
|
/* modify the correct directory entry */
|
|
|
|
for (dir = root; dir; dir = dir->next)
|
2006-01-02 02:54:02 +03:00
|
|
|
if (dir->numeric_prefix == index) {
|
2006-01-06 23:56:44 +03:00
|
|
|
if (file < 32)
|
|
|
|
dir->low_used &= ~(1 << file);
|
|
|
|
else
|
|
|
|
dir->high_used &= ~(1 << (file - 32));
|
2005-06-21 18:17:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-06-23 21:17:56 +04:00
|
|
|
* Initialise the filename provider.
|
2005-06-21 18:17:51 +04:00
|
|
|
*/
|
2006-04-22 03:50:36 +04:00
|
|
|
bool filename_initialise(void) {
|
|
|
|
char *directory, *start;
|
|
|
|
|
|
|
|
directory = strdup(TEMP_FILENAME_PREFIX);
|
|
|
|
if (!directory)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (start = directory; *start != '\0'; *start++) {
|
|
|
|
if (*start == '/') {
|
|
|
|
*start = '\0';
|
|
|
|
mkdir(directory, S_IRWXU);
|
|
|
|
*start = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG((directory));
|
|
|
|
mkdir(directory, S_IRWXU);
|
|
|
|
free(directory);
|
2005-06-21 18:17:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes all files in the cache directory that are not accounted for.
|
|
|
|
*/
|
2006-04-22 03:50:36 +04:00
|
|
|
void filename_flush(void) {
|
|
|
|
while (filename_flush_directory(TEMP_FILENAME_PREFIX, 0));
|
2006-01-06 23:56:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes some files in a directory that are not accounted for.
|
|
|
|
*
|
|
|
|
* A single call to this function may not delete all the files in
|
|
|
|
* a directory. It should be called until it returns false.
|
|
|
|
*
|
|
|
|
* \param folder the folder to search
|
|
|
|
* \param depth the folder depth
|
|
|
|
* \returns whether further calls may be needed
|
|
|
|
*/
|
2006-04-22 03:50:36 +04:00
|
|
|
bool filename_flush_directory(const char *folder, int depth) {
|
|
|
|
DIR *parent;
|
|
|
|
struct dirent *entry;
|
2006-01-06 23:56:44 +03:00
|
|
|
bool changed = false;
|
|
|
|
bool del;
|
|
|
|
int number, i;
|
|
|
|
int prefix = 0;
|
|
|
|
unsigned int prefix_mask = (63 << 12);
|
|
|
|
char child[256];
|
|
|
|
const char *prefix_start = NULL;
|
|
|
|
struct directory *dir = NULL;
|
|
|
|
|
|
|
|
/* find out directory details */
|
|
|
|
if (depth > 0)
|
|
|
|
prefix_start = folder + strlen(folder) - depth * 3 + 1;
|
|
|
|
for (i = 0; ((i < depth) && (i < 3)); i++) {
|
2006-04-22 03:50:36 +04:00
|
|
|
number = prefix_start[1] + prefix_start[0] * 10 - START_PREFIX;
|
2006-01-06 23:56:44 +03:00
|
|
|
prefix |= (number << (12 - i * 6));
|
|
|
|
prefix_mask |= (63 << (6 - i * 6));
|
|
|
|
prefix_start += 3;
|
|
|
|
}
|
|
|
|
if (depth == 3) {
|
|
|
|
for (dir = root; dir; dir = dir->next)
|
|
|
|
if (dir->numeric_prefix == prefix)
|
|
|
|
break;
|
|
|
|
if ((!dir) || (dir->numeric_prefix != prefix))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-04-22 03:50:36 +04:00
|
|
|
parent = opendir(folder);
|
|
|
|
|
|
|
|
while ((entry = readdir(parent))) {
|
|
|
|
if ((entry->d_ino == 0) || (!strcmp(entry->d_name, ".")) ||
|
|
|
|
(!strcmp(entry->d_name, "..")))
|
2006-01-06 23:56:44 +03:00
|
|
|
continue;
|
2006-04-22 03:50:36 +04:00
|
|
|
|
2006-01-06 23:56:44 +03:00
|
|
|
/* first 3 depths are directories only, then files only */
|
2006-04-22 03:50:36 +04:00
|
|
|
if (depth < 3)
|
|
|
|
del = (entry->d_type != DT_DIR);
|
|
|
|
else
|
|
|
|
del = (entry->d_type == DT_DIR);
|
|
|
|
|
2006-01-06 23:56:44 +03:00
|
|
|
/* check we are a file numbered '00' -> '63' */
|
2006-04-22 03:50:36 +04:00
|
|
|
if ((!del) && (entry->d_name[0] >= '0') &&
|
|
|
|
(entry->d_name[0] <= '6') &&
|
|
|
|
(entry->d_name[1] >= '0') &&
|
|
|
|
(entry->d_name[1] <= '9') &&
|
|
|
|
(entry->d_name[2] == '\0')) {
|
|
|
|
number = atoi(entry->d_name);
|
2006-01-06 23:56:44 +03:00
|
|
|
if ((number >= 0) && (number <= 63)) {
|
|
|
|
if (depth == 3) {
|
|
|
|
if (number < 32)
|
|
|
|
del = !(dir->low_used &
|
|
|
|
(1 << number));
|
|
|
|
else
|
|
|
|
del = !(dir->high_used &
|
|
|
|
(1 << (number - 32)));
|
|
|
|
} else {
|
2006-04-22 03:50:36 +04:00
|
|
|
del = true;
|
2006-01-06 23:56:44 +03:00
|
|
|
prefix &= ~(63 << (12 - depth * 6));
|
|
|
|
prefix |= (number << (12 - depth * 6));
|
|
|
|
for (dir = root; dir; dir = dir->next) {
|
|
|
|
number = dir->numeric_prefix &
|
|
|
|
prefix_mask;
|
|
|
|
if (number == prefix) {
|
|
|
|
del = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
del = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
del = true;
|
|
|
|
}
|
|
|
|
/* continue if we are a valid reference so far */
|
2006-04-22 03:50:36 +04:00
|
|
|
if ((!del) && (entry->d_type != DT_DIR))
|
2006-01-06 23:56:44 +03:00
|
|
|
continue;
|
|
|
|
/* delete or recurse */
|
2006-04-22 03:50:36 +04:00
|
|
|
snprintf(child, 256, "%s/%s", folder, entry->d_name);
|
2006-01-06 23:56:44 +03:00
|
|
|
child[255] = '\0';
|
|
|
|
if (del) {
|
2006-04-22 03:50:36 +04:00
|
|
|
if (entry->d_type == DT_DIR)
|
|
|
|
filename_delete_recursive(child);
|
|
|
|
if (remove(child))
|
|
|
|
LOG(("Failed to remove '%s'", child));
|
2006-01-06 23:56:44 +03:00
|
|
|
else
|
|
|
|
changed = true;
|
|
|
|
} else {
|
2006-04-22 03:50:36 +04:00
|
|
|
while (filename_flush_directory(child, depth + 1));
|
2006-01-06 23:56:44 +03:00
|
|
|
}
|
|
|
|
}
|
2006-04-22 03:50:36 +04:00
|
|
|
|
|
|
|
closedir(parent);
|
2006-01-06 23:56:44 +03:00
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively deletes the contents of a directory
|
|
|
|
*
|
|
|
|
* \param directory the directory to delete
|
|
|
|
* \return true on success, false otherwise
|
|
|
|
*/
|
2006-04-22 03:50:36 +04:00
|
|
|
bool filename_delete_recursive(char *folder) {
|
|
|
|
DIR *parent;
|
|
|
|
struct dirent *entry;
|
2006-01-06 23:56:44 +03:00
|
|
|
char child[256];
|
|
|
|
|
2006-04-22 03:50:36 +04:00
|
|
|
parent = opendir(folder);
|
|
|
|
|
|
|
|
while ((entry = readdir(parent))) {
|
|
|
|
if ((entry->d_ino == 0) || (!strcmp(entry->d_name, ".")) ||
|
|
|
|
(!strcmp(entry->d_name, "..")))
|
2006-01-06 23:56:44 +03:00
|
|
|
continue;
|
2006-04-22 03:50:36 +04:00
|
|
|
snprintf(child, 256, "%s/%s", folder, entry->d_name);
|
|
|
|
if (entry->d_type == DT_DIR) {
|
|
|
|
if (!filename_delete_recursive(child)) {
|
|
|
|
closedir(parent);
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-06 23:56:44 +03:00
|
|
|
}
|
2006-04-22 03:50:36 +04:00
|
|
|
if (remove(child)) {
|
|
|
|
LOG(("Failed to remove '%s'", child));
|
|
|
|
closedir(parent);
|
2006-01-06 23:56:44 +03:00
|
|
|
return false;
|
|
|
|
}
|
2006-04-22 03:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(parent);
|
|
|
|
return true;
|
2005-06-21 18:17:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new directory.
|
|
|
|
*
|
|
|
|
* \param prefix the prefix to use, or NULL to allocate a new one
|
2006-06-21 02:58:36 +04:00
|
|
|
* \return a new directory structure, or NULL on memory exhaustion or
|
|
|
|
* creation failure
|
2006-01-06 23:56:44 +03:00
|
|
|
*
|
2005-06-21 18:17:51 +04:00
|
|
|
* Empty directories are never deleted, except by an explicit call to
|
2006-04-22 03:50:36 +04:00
|
|
|
* filename_flush().
|
2005-06-21 18:17:51 +04:00
|
|
|
*/
|
2006-04-22 03:50:36 +04:00
|
|
|
static struct directory *filename_create_directory(const char *prefix) {
|
2005-06-21 18:17:51 +04:00
|
|
|
char *last_1, *last_2;
|
2006-01-02 02:54:02 +03:00
|
|
|
int index;
|
2005-06-21 18:17:51 +04:00
|
|
|
struct directory *old_dir, *new_dir, *prev_dir = NULL;
|
|
|
|
char dir_prefix[16];
|
2005-10-02 03:28:46 +04:00
|
|
|
|
2005-06-21 18:17:51 +04:00
|
|
|
/* get the lowest unique prefix, or use the provided one */
|
2005-10-02 03:28:46 +04:00
|
|
|
if (!prefix) {
|
2006-01-02 02:54:02 +03:00
|
|
|
for (index = 0, old_dir = root; old_dir; index++,
|
|
|
|
prev_dir = old_dir, old_dir = old_dir->next)
|
|
|
|
if (old_dir->numeric_prefix != index)
|
2005-06-21 18:17:51 +04:00
|
|
|
break;
|
2006-04-22 03:50:36 +04:00
|
|
|
sprintf(dir_prefix, "%.2i/%.2i/%.2i/",
|
2006-01-02 02:54:02 +03:00
|
|
|
((index >> 12) & 63),
|
|
|
|
((index >> 6) & 63),
|
|
|
|
((index >> 0) & 63));
|
2005-10-02 03:28:46 +04:00
|
|
|
prefix = dir_prefix;
|
2006-01-02 02:54:02 +03:00
|
|
|
} else {
|
2006-04-22 03:50:36 +04:00
|
|
|
/* prefix format is always '01/23/45/' */
|
2006-01-02 02:54:02 +03:00
|
|
|
index = ((prefix[7] + prefix[6] * 10 - START_PREFIX) |
|
|
|
|
((prefix[4] + prefix[3] * 10 - START_PREFIX) << 6) |
|
|
|
|
((prefix[1] + prefix[0] * 10 - START_PREFIX) << 12));
|
|
|
|
for (old_dir = root; old_dir; prev_dir = old_dir,
|
|
|
|
old_dir = old_dir->next) {
|
|
|
|
if (old_dir->numeric_prefix == index)
|
|
|
|
return old_dir;
|
|
|
|
else if (old_dir->numeric_prefix > index)
|
|
|
|
break;
|
|
|
|
}
|
2005-06-21 18:17:51 +04:00
|
|
|
}
|
2005-10-02 03:28:46 +04:00
|
|
|
|
2005-06-21 18:17:51 +04:00
|
|
|
/* allocate a new directory */
|
2006-01-02 02:54:02 +03:00
|
|
|
new_dir = (struct directory *)malloc(sizeof(struct directory));
|
2005-06-21 18:17:51 +04:00
|
|
|
if (!new_dir) {
|
2006-01-02 02:54:02 +03:00
|
|
|
LOG(("No memory for malloc()"));
|
2005-06-21 18:17:51 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-10-02 03:28:46 +04:00
|
|
|
strncpy(new_dir->prefix, prefix, 9);
|
|
|
|
new_dir->prefix[9] = '\0';
|
2006-01-02 02:54:02 +03:00
|
|
|
new_dir->low_used = new_dir->high_used = 0;
|
|
|
|
new_dir->numeric_prefix = index;
|
2005-06-21 18:17:51 +04:00
|
|
|
|
|
|
|
if (!prev_dir) {
|
|
|
|
new_dir->next = root;
|
|
|
|
root = new_dir;
|
|
|
|
} else {
|
|
|
|
new_dir->next = prev_dir->next;
|
|
|
|
prev_dir->next = new_dir;
|
|
|
|
}
|
2006-01-06 23:56:44 +03:00
|
|
|
|
2006-01-05 01:59:49 +03:00
|
|
|
/* if the previous directory has the same parent then we can simply
|
|
|
|
* create the child. */
|
|
|
|
if ((prev_dir) && (!strncmp(prev_dir->prefix, new_dir->prefix, 6))) {
|
2006-01-06 23:56:44 +03:00
|
|
|
new_dir->prefix[8] = '\0';
|
2006-04-22 03:50:36 +04:00
|
|
|
sprintf(filename_directory, "%s/%s",
|
|
|
|
TEMP_FILENAME_PREFIX,
|
|
|
|
new_dir->prefix);
|
|
|
|
new_dir->prefix[8] = '/';
|
2006-06-21 02:58:36 +04:00
|
|
|
if (!is_dir(filename_directory)) {
|
|
|
|
if (!mkdir(filename_directory, S_IRWXU))
|
|
|
|
return new_dir;
|
|
|
|
|
|
|
|
/* the user has probably deleted the parent directory
|
|
|
|
* whilst we are running if there is an error, so we
|
|
|
|
* don't report this yet and try to create the
|
|
|
|
* structure normally. */
|
|
|
|
LOG(("Failed to create optimised structure '%s'",
|
|
|
|
filename_directory));
|
|
|
|
}
|
2006-01-05 01:59:49 +03:00
|
|
|
}
|
2006-01-06 23:56:44 +03:00
|
|
|
|
2005-06-21 18:17:51 +04:00
|
|
|
/* create the directory structure */
|
2006-04-22 03:50:36 +04:00
|
|
|
sprintf(filename_directory, "%s/",
|
|
|
|
TEMP_FILENAME_PREFIX);
|
|
|
|
last_1 = filename_directory + strlen(TEMP_FILENAME_PREFIX) + 1;
|
2005-06-21 18:17:51 +04:00
|
|
|
last_2 = new_dir->prefix;
|
2005-10-02 03:28:46 +04:00
|
|
|
for (int i = 0; i < 3 && *last_2; i++) {
|
2005-06-21 18:17:51 +04:00
|
|
|
*last_1++ = *last_2++;
|
2006-04-22 03:50:36 +04:00
|
|
|
while (*last_2 && *last_2 != '/')
|
2005-06-21 18:17:51 +04:00
|
|
|
*last_1++ = *last_2++;
|
2006-01-06 23:56:44 +03:00
|
|
|
if (*last_2) {
|
2005-10-02 03:28:46 +04:00
|
|
|
last_1[0] = '\0';
|
2006-06-21 02:58:36 +04:00
|
|
|
if (!is_dir(filename_directory)) {
|
|
|
|
if (mkdir(filename_directory, S_IRWXU)) {
|
|
|
|
LOG(("Failed to create directory '%s'",
|
|
|
|
filename_directory));
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-01-05 01:59:49 +03:00
|
|
|
}
|
2005-10-02 03:28:46 +04:00
|
|
|
}
|
2005-06-21 18:17:51 +04:00
|
|
|
}
|
2006-06-21 02:58:36 +04:00
|
|
|
|
2005-06-21 18:17:51 +04:00
|
|
|
return new_dir;
|
|
|
|
}
|