static int file_cmd_executable(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { #ifdef X_OK return file_access(interp, argv[0], X_OK); #else /* If no X_OK, just assume true. */ Jim_SetResultBool(interp, 1); return JIM_OK; #endif }
/* ** COMMAND: deconstruct* ** ** Usage %fossil deconstruct ?OPTIONS? DESTINATION ** ** ** This command exports all artifacts of a given repository and ** writes all artifacts to the file system. The DESTINATION directory ** will be populated with subdirectories AA and files AA/BBBBBBBBB.., where ** AABBBBBBBBB.. is the 40 character artifact ID, AA the first 2 characters. ** If -L|--prefixlength is given, the length (default 2) of the directory ** prefix can be set to 0,1,..,9 characters. ** ** Options: ** -R|--repository REPOSITORY deconstruct given REPOSITORY ** -L|--prefixlength N set the length of the names of the DESTINATION ** subdirectories to N ** --private Include private artifacts. ** ** See also: rebuild, reconstruct */ void deconstruct_cmd(void){ const char *zDestDir; const char *zPrefixOpt; Stmt s; int privateFlag; /* get and check prefix length argument and build format string */ zPrefixOpt=find_option("prefixlength","L",1); if( !zPrefixOpt ){ prefixLength = 2; }else{ if( zPrefixOpt[0]>='0' && zPrefixOpt[0]<='9' && !zPrefixOpt[1] ){ prefixLength = (int)(*zPrefixOpt-'0'); }else{ fossil_fatal("N(%s) is not a valid prefix length!",zPrefixOpt); } } /* open repository and open query for all artifacts */ db_find_and_open_repository(OPEN_ANY_SCHEMA, 0); privateFlag = find_option("private",0,0)!=0; verify_all_options(); /* check number of arguments */ if( g.argc!=3 ){ usage ("?OPTIONS? DESTINATION"); } /* get and check argument destination directory */ zDestDir = g.argv[g.argc-1]; if( !*zDestDir || !file_isdir(zDestDir)) { fossil_fatal("DESTINATION(%s) is not a directory!",zDestDir); } #ifndef _WIN32 if( file_access(zDestDir, W_OK) ){ fossil_fatal("DESTINATION(%s) is not writeable!",zDestDir); } #else /* write access on windows is not checked, errors will be ** detected on blob_write_to_file */ #endif if( prefixLength ){ zFNameFormat = mprintf("%s/%%.%ds/%%s",zDestDir,prefixLength); }else{ zFNameFormat = mprintf("%s/%%s",zDestDir); } bag_init(&bagDone); ttyOutput = 1; processCnt = 0; if (!g.fQuiet) { fossil_print("0 (0%%)...\r"); fflush(stdout); } totalSize = db_int(0, "SELECT count(*) FROM blob"); db_prepare(&s, "SELECT rid, size FROM blob /*scan*/" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)" " AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid) %s", privateFlag==0 ? "AND rid NOT IN private" : "" ); while( db_step(&s)==SQLITE_ROW ){ int rid = db_column_int(&s, 0); int size = db_column_int(&s, 1); if( size>=0 ){ Blob content; content_get(rid, &content); rebuild_step(rid, size, &content); } } db_finalize(&s); db_prepare(&s, "SELECT rid, size FROM blob" " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid) %s", privateFlag==0 ? "AND rid NOT IN private" : "" ); while( db_step(&s)==SQLITE_ROW ){ int rid = db_column_int(&s, 0); int size = db_column_int(&s, 1); if( size>=0 ){ if( !bag_find(&bagDone, rid) ){ Blob content; content_get(rid, &content); rebuild_step(rid, size, &content); } } } db_finalize(&s); if(!g.fQuiet && ttyOutput ){ fossil_print("\n"); } /* free filename format string */ free(zFNameFormat); zFNameFormat = 0; }
int bu_file_executable(const char *path) { return file_access(path, X_OK); }
int bu_file_writable(const char *path) { return file_access(path, W_OK); }
int bu_file_readable(const char *path) { return file_access(path, R_OK); }
bool file_accessible (const std::string & filename) { return file_access(filename, R_OK|W_OK); }
bool file_writable (const std::string & filename) { return file_access(filename, W_OK); }
bool file_exists (const std::string & filename) { return file_access(filename, F_OK); }
/* ** Implementation of the /json/status page. ** */ cson_value * json_page_status(){ Stmt q = empty_Stmt; cson_object * oPay; /*cson_object * files;*/ int vid, nErr = 0; cson_object * tmpO; char * zTmp; i64 iMtime; cson_array * aFiles; if(!db_open_local(0)){ json_set_err(FSL_JSON_E_DB_NEEDS_CHECKOUT, NULL); return NULL; } oPay = cson_new_object(); cson_object_set(oPay, "repository", json_new_string(db_repository_filename())); cson_object_set(oPay, "localRoot", json_new_string(g.zLocalRoot)); vid = db_lget_int("checkout", 0); if(!vid){ json_set_err( FSL_JSON_E_UNKNOWN, "Can this even happen?" ); return 0; } /* TODO: dupe show_common_info() state */ tmpO = cson_new_object(); cson_object_set(oPay, "checkout", cson_object_value(tmpO)); zTmp = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); cson_object_set(tmpO, "uuid", json_new_string(zTmp) ); free(zTmp); cson_object_set( tmpO, "tags", json_tags_for_checkin_rid(vid, 0) ); /* FIXME: optimize the datetime/timestamp queries into 1 query. */ zTmp = db_text(0, "SELECT datetime(mtime) || " "' UTC' FROM event WHERE objid=%d", vid); cson_object_set(tmpO, "datetime", json_new_string(zTmp)); free(zTmp); iMtime = db_int64(0, "SELECT CAST(strftime('%%s',mtime) AS INTEGER) " "FROM event WHERE objid=%d", vid); cson_object_set(tmpO, "timestamp", cson_value_new_integer((cson_int_t)iMtime)); #if 0 /* TODO: add parent artifact info */ tmpO = cson_new_object(); cson_object_set( oPay, "parent", cson_object_value(tmpO) ); cson_object_set( tmpO, "uuid", TODO ); cson_object_set( tmpO, "timestamp", TODO ); #endif /* Now get the list of non-pristine files... */ aFiles = cson_new_array(); cson_object_set( oPay, "files", cson_array_value( aFiles ) ); db_prepare(&q, "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" " FROM vfile " " WHERE is_selected(id)" " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" ); while( db_step(&q)==SQLITE_ROW ){ const char *zPathname = db_column_text(&q,0); int isDeleted = db_column_int(&q, 1); int isChnged = db_column_int(&q,2); int isNew = db_column_int(&q,3)==0; int isRenamed = db_column_int(&q,4); cson_object * oFile; char const * zStatus = "???"; char * zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); if( isDeleted ){ zStatus = "deleted"; }else if( isNew ){ zStatus = "new" /* maintenance reminder: MUST come BEFORE the isChnged checks. */; }else if( isRenamed ){ zStatus = "renamed"; }else if( !file_wd_isfile_or_link(zFullName) ){ if( file_access(zFullName, F_OK)==0 ){ zStatus = "notAFile"; ++nErr; }else{ zStatus = "missing"; ++nErr; } }else if( 2==isChnged ){ zStatus = "updatedByMerge"; }else if( 3==isChnged ){ zStatus = "addedByMerge"; }else if( 4==isChnged ){ zStatus = "updatedByIntegrate"; }else if( 5==isChnged ){ zStatus = "addedByIntegrate"; }else if( 1==isChnged ){ if( file_contains_merge_marker(zFullName) ){ zStatus = "conflict"; }else{ zStatus = "edited"; } } oFile = cson_new_object(); cson_array_append( aFiles, cson_object_value(oFile) ); /* optimization potential: move these keys into cson_strings to take advantage of refcounting. */ cson_object_set( oFile, "name", json_new_string( zPathname ) ); cson_object_set( oFile, "status", json_new_string( zStatus ) ); free(zFullName); } cson_object_set( oPay, "errorCount", json_new_int( nErr ) ); db_finalize(&q); #if 0 /* TODO: add "merged with" status. First need (A) to decide on a structure and (B) to set up some tests for the multi-merge case.*/ db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid" " WHERE id<=0"); while( db_step(&q)==SQLITE_ROW ){ const char *zLabel = "MERGED_WITH"; switch( db_column_int(&q, 1) ){ case -1: zLabel = "CHERRYPICK "; break; case -2: zLabel = "BACKOUT "; break; case -4: zLabel = "INTEGRATE "; break; } blob_append(report, zPrefix, nPrefix); blob_appendf(report, "%s %s\n", zLabel, db_column_text(&q, 0)); } db_finalize(&q); if( nErr ){ fossil_fatal("aborting due to prior errors"); } #endif return cson_object_value( oPay ); }
/* ** COMMAND: add ** ** Usage: %fossil add ?OPTIONS? FILE1 ?FILE2 ...? ** ** Make arrangements to add one or more files or directories to the ** current checkout at the next commit. ** ** When adding files or directories recursively, filenames that begin ** with "." are excluded by default. To include such files, add ** the "--dotfiles" option to the command-line. ** ** The --ignore option is a comma-separate list of glob patterns for files ** to be excluded. Example: '*.o,*.obj,*.exe' If the --ignore option ** does not appear on the command line then the "ignore-glob" setting is ** used. ** ** The --case-sensitive option determines whether or not filenames should ** be treated case sensitive or not. If the option is not given, the default ** depends on the global setting, or the operating system default, if not set. ** ** Options: ** ** --case-sensitive <BOOL> override case-sensitive setting ** --dotfiles include files beginning with a dot (".") ** --ignore <CSG> ignore files matching patterns from the ** comma separated list of glob patterns. ** ** See also: addremove, rm */ void add_cmd(void){ int i; /* Loop counter */ int vid; /* Currently checked out version */ int nRoot; /* Full path characters in g.zLocalRoot */ const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */ Glob *pIgnore; /* Ignore everything matching this glob pattern */ int caseSensitive; /* True if filenames are case sensitive */ unsigned scanFlags = 0; /* Flags passed to vfile_scan() */ zIgnoreFlag = find_option("ignore",0,1); if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; capture_case_sensitive_option(); db_must_be_within_tree(); caseSensitive = filenames_are_case_sensitive(); if( zIgnoreFlag==0 ){ zIgnoreFlag = db_get("ignore-glob", 0); } vid = db_lget_int("checkout",0); if( vid==0 ){ fossil_panic("no checkout to add to"); } db_begin_transaction(); db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)"); #if defined(_WIN32) db_multi_exec( "CREATE INDEX IF NOT EXISTS vfile_pathname " " ON vfile(pathname COLLATE nocase)" ); #endif pIgnore = glob_create(zIgnoreFlag); nRoot = strlen(g.zLocalRoot); /* Load the names of all files that are to be added into sfile temp table */ for(i=2; i<g.argc; i++){ char *zName; int isDir; Blob fullName; file_canonical_name(g.argv[i], &fullName, 0); zName = blob_str(&fullName); isDir = file_wd_isdir(zName); if( isDir==1 ){ vfile_scan(&fullName, nRoot-1, scanFlags, pIgnore); }else if( isDir==0 ){ fossil_warning("not found: %s", zName); }else if( file_access(zName, R_OK) ){ fossil_fatal("cannot open %s", zName); }else{ char *zTreeName = &zName[nRoot]; db_multi_exec( "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)", zTreeName ); } blob_reset(&fullName); } glob_free(pIgnore); add_files_in_sfile(vid, caseSensitive); db_end_transaction(0); }
int main(int argc, char **argv) { if(argc == 1) { usage(); exit(1); } while((cret = getopt(argc,argv,"bwetvf:s:l:u: ")) != EOF) { switch(cret) { case 'f': /* Force factor */ x=atoi(optarg); if(x < 0) x=1; break; case 's': /* Size of files */ sz=atoi(optarg); if(optarg[strlen(optarg)-1]=='k' || optarg[strlen(optarg)-1]=='K') { sz = (1024 * atoi(optarg)); } if(optarg[strlen(optarg)-1]=='m' || optarg[strlen(optarg)-1]=='M') { sz = (1024 * 1024 * atoi(optarg)); } if(sz < 0) sz=1; break; case 'l': /* lower force value */ lower=atoi(optarg); range=1; if(lower < 0) lower=1; break; case 'v': /* version */ splash(); exit(0); break; case 'u': /* upper force value */ upper=atoi(optarg); range=1; if(upper < 0) upper=1; break; case 't': /* verbose */ verbose=1; break; case 'e': /* Excel */ excel=1; break; case 'b': /* Best */ best=1; break; case 'w': /* Worst */ worst=1; break; } } mbuffer=(char *)malloc(sz); memset(mbuffer,'a',sz); if(!excel) printf("\nFileop: File size is %d, Output is in Ops/sec. (A=Avg, B=Best, W=Worst)\n",sz); if(!verbose) { #ifdef Windows printf(" . %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n", "mkdir","rmdir","create","read","write","close","stat", "access","chmod","readdir","delete"," Total_files"); #else printf(" . %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n", "mkdir","rmdir","create","read","write","close","stat", "access","chmod","readdir","link ","unlink","delete", " Total_files"); #endif } if(x==0) x=1; if(range==0) lower=upper=x; for(i=lower; i<=upper; i++) { clear_stats(); x=i; /* * Dir Create test */ dir_create(x); if(verbose) { printf("mkdir: Dirs = %9lld ",stats[_STAT_DIR_CREATE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_DIR_CREATE].total_time); printf(" Avg mkdir(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time, stats[_STAT_DIR_CREATE].total_time/stats[_STAT_DIR_CREATE].counter); printf(" Best mkdir(s)/sec = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_CREATE].best,stats[_STAT_DIR_CREATE].best); printf(" Worst mkdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_CREATE].worst,stats[_STAT_DIR_CREATE].worst); } /* * Dir delete test */ dir_delete(x); if(verbose) { printf("rmdir: Dirs = %9lld ",stats[_STAT_DIR_DELETE].counter); printf("Total Time = %12.9f seconds\n",stats[_STAT_DIR_DELETE].total_time); printf(" Avg rmdir(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time, stats[_STAT_DIR_DELETE].total_time/stats[_STAT_DIR_DELETE].counter); printf(" Best rmdir(s)/sec = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_DELETE].best,stats[_STAT_DIR_DELETE].best); printf(" Worst rmdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_DELETE].worst,stats[_STAT_DIR_DELETE].worst); } /* * Create test */ file_create(x); if(verbose) { printf("create: Files = %9lld ",stats[_STAT_CREATE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_CREATE].total_time); printf(" Avg create(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time, stats[_STAT_CREATE].total_time/stats[_STAT_CREATE].counter); printf(" Best create(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_CREATE].best,stats[_STAT_CREATE].best); printf(" Worst create(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_CREATE].worst,stats[_STAT_CREATE].worst); printf("write: Files = %9lld ",stats[_STAT_WRITE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_WRITE].total_time); printf(" Avg write(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time, stats[_STAT_WRITE].total_time/stats[_STAT_WRITE].counter); printf(" Best write(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_WRITE].best,stats[_STAT_WRITE].best); printf(" Worst write(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_WRITE].worst,stats[_STAT_WRITE].worst); printf("close: Files = %9lld ",stats[_STAT_CLOSE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_CLOSE].total_time); printf(" Avg close(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time, stats[_STAT_CLOSE].total_time/stats[_STAT_CLOSE].counter); printf(" Best close(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_CLOSE].best,stats[_STAT_CLOSE].best); printf(" Worst close(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_CLOSE].worst,stats[_STAT_CLOSE].worst); } /* * Stat test */ file_stat(x); if(verbose) { printf("stat: Files = %9lld ",stats[_STAT_STAT].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_STAT].total_time); printf(" Avg stat(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time, stats[_STAT_STAT].total_time/stats[_STAT_STAT].counter); printf(" Best stat(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_STAT].best,stats[_STAT_STAT].best); printf(" Worst stat(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_STAT].worst,stats[_STAT_STAT].worst); } /* * Read test */ file_read(x); if(verbose) { printf("read: Files = %9lld ",stats[_STAT_READ].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_READ].total_time); printf(" Avg read(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_READ].counter/stats[_STAT_READ].total_time, stats[_STAT_READ].total_time/stats[_STAT_READ].counter); printf(" Best read(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_READ].best,stats[_STAT_READ].best); printf(" Worst read(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_READ].worst,stats[_STAT_READ].worst); } /* * Access test */ file_access(x); if(verbose) { printf("access: Files = %9lld ",stats[_STAT_ACCESS].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_ACCESS].total_time); printf(" Avg access(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time, stats[_STAT_ACCESS].total_time/stats[_STAT_ACCESS].counter); printf(" Best access(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_ACCESS].best,stats[_STAT_ACCESS].best); printf(" Worst access(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_ACCESS].worst,stats[_STAT_ACCESS].worst); } /* * Chmod test */ file_chmod(x); if(verbose) { printf("chmod: Files = %9lld ",stats[_STAT_CHMOD].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_CHMOD].total_time); printf(" Avg chmod(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time, stats[_STAT_CHMOD].total_time/stats[_STAT_CHMOD].counter); printf(" Best chmod(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_CHMOD].best,stats[_STAT_CHMOD].best); printf(" Worst chmod(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_CHMOD].worst,stats[_STAT_CHMOD].worst); } /* * readdir test */ file_readdir(x); if(verbose) { printf("readdir: Files = %9lld ",stats[_STAT_READDIR].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_READDIR].total_time); printf(" Avg readdir(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time, stats[_STAT_READDIR].total_time/stats[_STAT_READDIR].counter); printf(" Best readdir(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_READDIR].best,stats[_STAT_READDIR].best); printf(" Worst readdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_READDIR].worst,stats[_STAT_READDIR].worst); } #if !defined(Windows) /* * link test */ file_link(x); if(verbose) { printf("link: Files = %9lld ",stats[_STAT_LINK].counter); printf("Total Time = %12.9f seconds\n",stats[_STAT_LINK].total_time); printf(" Avg link(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time, stats[_STAT_LINK].total_time/stats[_STAT_LINK].counter); printf(" Best link(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_LINK].best,stats[_STAT_LINK].best); printf(" Worst link(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_LINK].worst,stats[_STAT_LINK].worst); } /* * unlink test */ file_unlink(x); if(verbose) { printf("unlink: Files = %9lld ",stats[_STAT_UNLINK].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_UNLINK].total_time); printf(" Avg unlink(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time, stats[_STAT_UNLINK].total_time/stats[_STAT_UNLINK].counter); printf(" Best unlink(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_UNLINK].best,stats[_STAT_UNLINK].best); printf(" Worst unlink(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_UNLINK].worst,stats[_STAT_UNLINK].worst); } #endif /* * Delete test */ file_delete(x); if(verbose) { printf("delete: Files = %9lld ",stats[_STAT_DELETE].counter); printf("Total Time = %12.9f seconds\n", stats[_STAT_DELETE].total_time); printf(" Avg delete(s)/sec = %12.2f (%12.9f seconds/op)\n", stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time, stats[_STAT_DELETE].total_time/stats[_STAT_DELETE].counter); printf(" Best delete(s)/sec = %12.2f (%12.9f seconds/op)\n", 1/stats[_STAT_DELETE].best,stats[_STAT_DELETE].best); printf(" Worst delete(s)/sec = %12.2f (%12.9f seconds/op)\n\n", 1/stats[_STAT_DELETE].worst,stats[_STAT_DELETE].worst); } if(!verbose) { printf("%c %4d %6.0f ",'A',x,stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time); printf("%6.0f ",stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time); printf("%6.0f ",stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time); printf("%6.0f ",stats[_STAT_READ].counter/stats[_STAT_READ].total_time); printf("%6.0f ",stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time); printf("%6.0f ",stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time); printf("%6.0f ",stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time); printf("%6.0f ",stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time); printf("%6.0f ",stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time); printf("%6.0f ",stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time); #ifndef Windows printf("%6.0f ",stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time); printf("%6.0f ",stats[_STAT_UNLINK].counter/stats[_STAT_UNLINK].total_time); #endif printf("%6.0f ",stats[_STAT_DELETE].counter/stats[_STAT_DELETE].total_time); printf("%12d ",x*x*x); printf("\n"); fflush(stdout); if(best) { printf("%c %4d %6.0f ",'B',x, 1/stats[_STAT_DIR_CREATE].best); printf("%6.0f ",1/stats[_STAT_DIR_DELETE].best); printf("%6.0f ",1/stats[_STAT_CREATE].best); printf("%6.0f ",1/stats[_STAT_READ].best); printf("%6.0f ",1/stats[_STAT_WRITE].best); printf("%6.0f ",1/stats[_STAT_CLOSE].best); printf("%6.0f ",1/stats[_STAT_STAT].best); printf("%6.0f ",1/stats[_STAT_ACCESS].best); printf("%6.0f ",1/stats[_STAT_CHMOD].best); printf("%6.0f ",1/stats[_STAT_READDIR].best); #ifndef Windows printf("%6.0f ",1/stats[_STAT_LINK].best); printf("%6.0f ",1/stats[_STAT_UNLINK].best); #endif printf("%6.0f ",1/stats[_STAT_DELETE].best); printf("%12d ",x*x*x); printf("\n"); fflush(stdout); } if(worst) { printf("%c %4d %6.0f ",'W',x, 1/stats[_STAT_DIR_CREATE].worst); printf("%6.0f ",1/stats[_STAT_DIR_DELETE].worst); printf("%6.0f ",1/stats[_STAT_CREATE].worst); printf("%6.0f ",1/stats[_STAT_READ].worst); printf("%6.0f ",1/stats[_STAT_WRITE].worst); printf("%6.0f ",1/stats[_STAT_CLOSE].worst); printf("%6.0f ",1/stats[_STAT_STAT].worst); printf("%6.0f ",1/stats[_STAT_ACCESS].worst); printf("%6.0f ",1/stats[_STAT_CHMOD].worst); printf("%6.0f ",1/stats[_STAT_READDIR].worst); #ifndef Windows printf("%6.0f ",1/stats[_STAT_LINK].worst); printf("%6.0f ",1/stats[_STAT_UNLINK].worst); #endif printf("%6.0f ",1/stats[_STAT_DELETE].worst); printf("%12d ",x*x*x); printf("\n"); fflush(stdout); } } } return(0); }
static int file_cmd_exists(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { return file_access(interp, argv[0], F_OK); }
static int file_cmd_writable(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { return file_access(interp, argv[0], W_OK); }
/* ** COMMAND: all ** ** Usage: %fossil all (list|ls|pull|push|rebuild|sync) ** ** The ~/.fossil file records the location of all repositories for a ** user. This command performs certain operations on all repositories ** that can be useful before or after a period of disconnected operation. ** ** On Win32 systems, the file is named "_fossil" and is located in ** %LOCALAPPDATA%, %APPDATA% or %HOMEPATH%. ** ** Available operations are: ** ** ignore Arguments are repositories that should be ignored ** by subsequent list, pull, push, rebuild, and sync. ** ** list | ls Display the location of all repositories. ** The --ckout option causes all local checkouts to be ** list instead. ** ** changes Shows all local checkouts that have uncommitted changes ** ** pull Run a "pull" operation on all repositories ** ** push Run a "push" on all repositories ** ** rebuild Rebuild on all repositories ** ** sync Run a "sync" on all repositories ** ** Repositories are automatically added to the set of known repositories ** when one of the following commands are run against the repository: clone, ** info, pull, push, or sync. Even previously ignored repositories are ** added back to the list of repositories by these commands. */ void all_cmd(void){ int n; Stmt q; const char *zCmd; char *zSyscmd; char *zFossil; char *zQFilename; int useCheckouts = 0; int quiet = 0; int testRun = 0; int stopOnError = find_option("dontstop",0,0)==0; int rc; Bag outOfDate; /* The undocumented --test option causes no changes to occur to any ** repository, but instead show what would have happened. Intended for ** test and debugging use. */ testRun = find_option("test",0,0)!=0; if( g.argc<3 ){ usage("changes|list|ls|pull|push|rebuild|sync"); } n = strlen(g.argv[2]); db_open_config(1); zCmd = g.argv[2]; if( strncmp(zCmd, "list", n)==0 || strncmp(zCmd,"ls",n)==0 ){ zCmd = "list"; useCheckouts = find_option("ckout","c",0)!=0; }else if( strncmp(zCmd, "push", n)==0 ){ zCmd = "push -autourl -R"; }else if( strncmp(zCmd, "pull", n)==0 ){ zCmd = "pull -autourl -R"; }else if( strncmp(zCmd, "rebuild", n)==0 ){ zCmd = "rebuild"; }else if( strncmp(zCmd, "sync", n)==0 ){ zCmd = "sync -autourl -R"; }else if( strncmp(zCmd, "test-integrity", n)==0 ){ zCmd = "test-integrity"; }else if( strncmp(zCmd, "changes", n)==0 ){ zCmd = "changes --quiet --header --chdir"; useCheckouts = 1; stopOnError = 0; quiet = 1; }else if( strncmp(zCmd, "ignore", n)==0 ){ int j; verify_all_options(); db_begin_transaction(); for(j=3; j<g.argc; j++){ char *zSql = mprintf("DELETE FROM global_config" " WHERE name GLOB 'repo:%q'", g.argv[j]); if( testRun ){ fossil_print("%s\n", zSql); }else{ db_multi_exec("%s", zSql); } fossil_free(zSql); } db_end_transaction(0); return; }else{ fossil_fatal("\"all\" subcommand should be one of: " "changes ignore list ls push pull rebuild sync"); } verify_all_options(); zFossil = quoteFilename(g.nameOfExe); if( useCheckouts ){ db_prepare(&q, "SELECT substr(name, 7) COLLATE nocase, max(rowid)" " FROM global_config" " WHERE substr(name, 1, 6)=='ckout:'" " GROUP BY 1 ORDER BY 1" ); }else{ db_prepare(&q, "SELECT substr(name, 6) COLLATE nocase, max(rowid)" " FROM global_config" " WHERE substr(name, 1, 5)=='repo:'" " GROUP BY 1 ORDER BY 1" ); } bag_init(&outOfDate); while( db_step(&q)==SQLITE_ROW ){ const char *zFilename = db_column_text(&q, 0); int rowid = db_column_int(&q, 1); if( file_access(zFilename, 0) || !file_is_canonical(zFilename) ){ bag_insert(&outOfDate, rowid); continue; } if( useCheckouts && file_isdir(zFilename)!=1 ){ bag_insert(&outOfDate, rowid); continue; } if( zCmd[0]=='l' ){ fossil_print("%s\n", zFilename); continue; } zQFilename = quoteFilename(zFilename); zSyscmd = mprintf("%s %s %s", zFossil, zCmd, zQFilename); if( !quiet || testRun ){ fossil_print("%s\n", zSyscmd); fflush(stdout); } rc = testRun ? 0 : fossil_system(zSyscmd); free(zSyscmd); free(zQFilename); if( stopOnError && rc ){ break; } } db_finalize(&q); /* If any repositories whose names appear in the ~/.fossil file could not ** be found, remove those names from the ~/.fossil file. */ if( bag_count(&outOfDate)>0 ){ Blob sql; char *zSep = "("; int rowid; blob_zero(&sql); blob_appendf(&sql, "DELETE FROM global_config WHERE rowid IN "); for(rowid=bag_first(&outOfDate); rowid>0; rowid=bag_next(&outOfDate,rowid)){ blob_appendf(&sql, "%s%d", zSep, rowid); zSep = ","; } blob_appendf(&sql, ")"); if( testRun ){ fossil_print("%s\n", blob_str(&sql)); }else{ db_multi_exec(blob_str(&sql)); } blob_reset(&sql); } }