Esempio n. 1
0
const char* makeTempDir(const char* dirPrefix) {
  const char* tmpdirprefix = astr(getTempDir(), "/", dirPrefix);
  const char* tmpdirsuffix = ".deleteme";

  pid_t mypid = getpid();
#ifdef DEBUGTMPDIR
  mypid = 0;
#endif

  char mypidstr[MAX_CHARS_PER_PID];
  snprintf(mypidstr, MAX_CHARS_PER_PID, "-%d", (int)mypid);

  struct passwd* passwdinfo = getpwuid(geteuid());
  const char* userid;
  if (passwdinfo == NULL) {
    userid = "anon";
  } else {
    userid = passwdinfo->pw_name;
  }
  char* myuserid = strdup(userid);
  removeSpacesBackslashesFromString(myuserid);

  const char* tmpDir = astr(tmpdirprefix, myuserid, mypidstr, tmpdirsuffix);
  ensureDirExists(tmpDir, "making temporary directory");

  free(myuserid); myuserid = NULL;

  return tmpDir;
}
Esempio n. 2
0
fs::path ensureParentDirExists(const boost::filesystem::path &filename) {
    if(!fs::exists(filename))  {
        // Ensure parent directory exist
        fs::path dir = filename.parent_path();
        ensureDirExists(dir);
    }
    return filename;
}
Esempio n. 3
0
static void ensureTmpDirExists() {
  if (saveCDir[0] == '\0') {
    if (tmpdirname == NULL) {
      tmpdirname = makeTempDir("chpl-");
      intDirName = tmpdirname;
    }
  } else {
    if (intDirName != saveCDir) {
      intDirName = saveCDir;
      ensureDirExists(saveCDir, "ensuring --savec directory exists");
    }
  }
}
Esempio n. 4
0
static void ensureTmpDirExists() {
  if (saveCDir[0] == '\0') {
    if (tmpdirname == NULL) {
      const char* tmpdirprefix = "/tmp/chpl-";
      const char* tmpdirsuffix = ".deleteme";

      pid_t mypid = getpid();
#ifdef DEBUGTMPDIR
      mypid = 0;
#endif

      char mypidstr[MAX_CHARS_PER_PID];
      snprintf(mypidstr, MAX_CHARS_PER_PID, "-%d", (int)mypid);

      struct passwd* passwdinfo = getpwuid(geteuid());
      const char* userid;
      if (passwdinfo == NULL) {
        userid = "anon";
      } else {
        userid = passwdinfo->pw_name;
      }
      char* myuserid = strdup(userid);
      removeSpacesFromString(myuserid);

      tmpdirname = astr(tmpdirprefix, myuserid, mypidstr, tmpdirsuffix);
      intDirName = tmpdirname;
      ensureDirExists(intDirName, "making temporary directory");

      free(myuserid); myuserid = NULL;
    }
  } else {
    if (intDirName != saveCDir) {
      intDirName = saveCDir;
      ensureDirExists(saveCDir, "ensuring --savec directory exists");
    }
  }
}
Esempio n. 5
0
File: far.c Progetto: ASchurman/Far
/* Extracts the file named filename with size fileSize from archive. The file
 * pointer in archive must be pointing to the beginning of the body of the file
 * to extract. Prints a message to stderr if the extraction cannot be done.
 * Moves the file pointer to the end of the body of the file extracted.
 * Returns -1 if the archive is corrupted, else returns 0. */
char extractFile(FILE* archive, char* filename, unsigned int fileSize)
{
    int currentLen = 0;
    char* currentStr = NULL;
    
    while(currentLen < strlen(filename))
    {
        // count chars in filename up to the next slash, and include the slash
        currentLen += strcspn(&(filename[currentLen]), "/") + 1;
        
        currentStr = malloc(sizeof(char) * (currentLen + 1));
        
        strncpy(currentStr, filename, currentLen);
        currentStr[currentLen] = '\0';
        
        if(currentStr[currentLen - 1] == '/') // if it's a directory
        {
            ensureDirExists(currentStr);
        }
        else // it's a regular file
        {
            FILE* extractedFile = fopen(filename, "wb+");
            
            if(extractedFile)
            {
                for(unsigned int i = 0; i < fileSize; i++)
                {
                    int c = fgetc(archive);
                    if(c == EOF)
                    {
                        return -1;
                    }
                    else
                    {
                        fputc(c, extractedFile);
                    }
                }
                fclose(extractedFile);
            }
            else
            {
                fileOpenError(filename);
            }
        }
    }
    
    if(currentStr) free(currentStr);
    return 0;
}
Esempio n. 6
0
static void setupLogfiles() {
  if (logging() || fdump_html || *deletedIdFilename)
    ensureDirExists(log_dir, "ensuring directory for log files exists");

  if (log_dir[strlen(log_dir)-1] != '/') 
    strcat(log_dir, "/");

  if (fdump_html) {
    if (!(html_index_file = fopen(astr(log_dir, "index.html"), "w"))) {
      USR_FATAL("cannot open html index file \"%s\" for writing", astr(log_dir, "index.html"));
    }
    dump_index_header(html_index_file);
    fprintf(html_index_file, "<TABLE CELLPADDING=\"0\" CELLSPACING=\"0\">");
  }
  if (deletedIdFilename[0] != '\0') {
    deletedIdHandle = fopen(deletedIdFilename, "w");
    if (!deletedIdHandle) {
      USR_FATAL("cannot open file to log deleted AST ids\"%s\" for writing", deletedIdFilename);
    }
  }
}
Esempio n. 7
0
void PluginEnvironment::initialize() {
    LOG_DEBUG << "Initializing in" << root();
    ensureDirExists(Constants::STATES_DIR);
    ensureDirExists(Constants::DB_DIR);
}