コード例 #1
0
ファイル: blob.c プロジェクト: kassanmoor/fossildocker
/*
** Write the content of a blob into a file.
**
** If the filename is blank or "-" then write to standard output.
**
** Return the number of bytes written.
*/
int blob_write_to_file(Blob *pBlob, const char *zFilename){
  FILE *out;
  int nWrote;

  if( zFilename[0]==0 || (zFilename[0]=='-' && zFilename[1]==0) ){
    nWrote = blob_size(pBlob);
#if defined(_WIN32)
    if( fossil_utf8_to_console(blob_buffer(pBlob), nWrote, 0) >= 0 ){
      return nWrote;
    }
#endif
    fwrite(blob_buffer(pBlob), 1, nWrote, stdout);
  }else{
    file_mkfolder(zFilename, 1);
    out = fossil_fopen(zFilename, "wb");
    if( out==0 ){
      fossil_fatal_recursive("unable to open file \"%s\" for writing",
                             zFilename);
      return 0;
    }
    blob_is_init(pBlob);
    nWrote = fwrite(blob_buffer(pBlob), 1, blob_size(pBlob), out);
    fclose(out);
    if( nWrote!=blob_size(pBlob) ){
      fossil_fatal_recursive("short write: %d of %d bytes to %s", nWrote,
         blob_size(pBlob), zFilename);
    }
  }
  return nWrote;
}
コード例 #2
0
ファイル: file.c プロジェクト: digsrc/fossil
/*
** Copy the content of a file from one place to another.
*/
void file_copy(const char *zFrom, const char *zTo){
  FILE *in, *out;
  int got;
  char zBuf[8192];
  in = fossil_fopen(zFrom, "rb");
  if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom);
  file_mkfolder(zTo, 0, 0);
  out = fossil_fopen(zTo, "wb");
  if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo);
  while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){
    fwrite(zBuf, 1, got, out);
  }
  fclose(in);
  fclose(out);
}
コード例 #3
0
ファイル: update.c プロジェクト: digsrc/fossil
/*
** Create empty directories specified by the empty-dirs setting.
*/
void ensure_empty_dirs_created(void) {
    char *zEmptyDirs = db_get("empty-dirs", 0);
    if( zEmptyDirs!=0 ) {
        int i;
        Blob dirName;
        Blob dirsList;

        zEmptyDirs = fossil_strdup(zEmptyDirs);
        for(i=0; zEmptyDirs[i]; i++) {
            if( zEmptyDirs[i]==',' ) zEmptyDirs[i] = ' ';
        }
        blob_init(&dirsList, zEmptyDirs, -1);
        while( blob_token(&dirsList, &dirName) ) {
            char *zDir = blob_str(&dirName);
            char *zPath = mprintf("%s/%s", g.zLocalRoot, zDir);
            switch( file_wd_isdir(zPath) ) {
            case 0: { /* doesn't exist */
                fossil_free(zPath);
                zPath = mprintf("%s/%s/x", g.zLocalRoot, zDir);
                if( file_mkfolder(zPath, 0, 1)!=0 ) {
                    fossil_warning("couldn't create directory %s as "
                                   "required by empty-dirs setting", zDir);
                }
                break;
            }
            case 1: { /* exists, and is a directory */
                /* do nothing - required directory exists already */
                break;
            }
            case 2: { /* exists, but isn't a directory */
                fossil_warning("file %s found, but a directory is required "
                               "by empty-dirs setting", zDir);
            }
            }
            fossil_free(zPath);
            blob_reset(&dirName);
        }
        blob_reset(&dirsList);
        fossil_free(zEmptyDirs);
    }
}