Ejemplo n.º 1
0
void
fixInstallPaths (char **const *paths) {
  static const char *programDirectory = NULL;

  if (!programDirectory) {
    if (!(programDirectory = getPathDirectory(programPath))) {
      logMessage(LOG_WARNING, gettext("cannot determine program directory"));
      programDirectory = ".";
    }

    logMessage(LOG_DEBUG, "program directory: %s", programDirectory);
  }

  while (*paths) {
    if (**paths && ***paths) {
      char *newPath = makePath(programDirectory, **paths);

      if (!newPath) {
        logMessage(LOG_WARNING, "%s: %s", gettext("cannot fix install path"), **paths);
      } else if (!isAbsolutePath(**paths=newPath)) {
        logMessage(LOG_WARNING, "%s: %s", gettext("install path not absolute"), **paths);
      }
    }

    paths += 1;
  }
}
Ejemplo n.º 2
0
Archivo: file.c Proyecto: Feechka/UOBP
int
ensureDirectory (const char *path) {
  if (testDirectoryPath(path)) return 1;

  if (errno == EEXIST) {
    logMessage(LOG_ERR, "not a directory: %s", path);
  } else if (errno != ENOENT) {
    logMessage(LOG_ERR, "cannot access directory: %s: %s", path, strerror(errno));
  } else {
    {
      char *directory = getPathDirectory(path);
      if (!directory) return 0;

      {
         int exists = ensureDirectory(directory);
         free(directory);
         if (!exists) return 0;
      }
    }

    if (createDirectory(path)) {
      logMessage(LOG_NOTICE, "directory created: %s", path);
      return 1;
    }
  }

  return 0;
}
Ejemplo n.º 3
0
Archivo: file.c Proyecto: Feechka/UOBP
FILE *
openDataFile (const char *path, const char *mode, int optional) {
  const char *name = locatePathName(path);
  const char *overrideDirectory = getOverrideDirectory();
  char *overridePath;
  FILE *file;

  if (!overrideDirectory) {
    overridePath = NULL;
  } else if ((overridePath = makePath(overrideDirectory, name))) {
    if (testFilePath(overridePath)) {
      file = openFile(overridePath, mode, optional);
      goto done;
    }
  }

  if (!(file = openFile(path, mode, optional))) {
    if ((*mode == 'w') || (*mode == 'a')) {
      if (errno == ENOENT) {
        char *directory = getPathDirectory(path);

        if (directory) {
          int exists = ensureDirectory(directory);
          free(directory);

          if (exists) {
            file = openFile(path, mode, optional);
            goto done;
          }
        }
      }

      if (((errno == EACCES) || (errno == EROFS)) && overridePath) {
        if (ensureDirectory(overrideDirectory)) {
          file = openFile(overridePath, mode, optional);
          goto done;
        }
      }
    }
  }

done:
  if (overridePath) free(overridePath);
  return file;
}
Ejemplo n.º 4
0
int
fixInstallPath (char **path) {
  static const char *programDirectory = NULL;

  if (!programDirectory) {
    if ((programDirectory = getPathDirectory(programPath))) {
      registerProgramMemory("program-directory", &programDirectory);
    } else {
      logMessage(LOG_WARNING, gettext("cannot determine program directory"));
      programDirectory = ".";
    }

    logMessage(LOG_DEBUG, "program directory: %s", programDirectory);
  }

  {
    const char *problem = strtext("cannot fix install path");
    char *newPath = makePath(programDirectory, *path);

    if (newPath) {
      if (changeStringSetting(path, newPath)) {
        if (isAbsolutePath(*path)) {
          problem = NULL;
        } else {
          problem = strtext("install path not absolute");
        }
      }

      free(newPath);
    }

    if (problem) {
      logMessage(LOG_WARNING, "%s: %s", gettext(problem), *path);
      return 0;
    }
  }

  return 1;
}