Beispiel #1
0
flist *
next_valid(Window *win, flist *file, int c)
{
    flist *ftmp = file;
    int fix_selected = 0;
    if (!file)
        return file;
    if (file->flags & F_SELECTED)
        fix_selected = 1;
    switch (c) {
    case KEY_HOME:
    case KEY_DOWN:
    case KEY_NPAGE:
        while (!check_file(file))
            file = delete_file(win, file);
        break;
    case KEY_END:
    case KEY_UP:
    case KEY_PPAGE:
        while (!check_file(file)) {
            ftmp = file->prev;
            delete_file(win, file);
            file = ftmp;
        }
        break;
    }
    if (fix_selected) {
        win->contents.list->selected = file;
        file->flags |= F_SELECTED;
    }
    return file;
}
TEST(LogFileOutput, startup_truncation) {
  const char* filename = "start-truncate-test";
  const char* archived_filename = "start-truncate-test.0";

  delete_file(filename);
  delete_file(archived_filename);

  // Use the same log file twice and expect it to be overwritten/truncated
  init_log_file(filename, "filecount=0");
  ASSERT_TRUE(file_exists(filename))
    << "configured logging to file '" << filename << "' but file was not found";

  init_log_file(filename, "filecount=0");
  ASSERT_TRUE(file_exists(filename))
    << "configured logging to file '" << filename << "' but file was not found";
  EXPECT_FALSE(file_exists(archived_filename))
    << "existing log file was not properly truncated when filecount was 0";

  // Verify that the file was really truncated and not just appended
  EXPECT_TRUE(file_contains_substring(filename, LOG_TEST_STRING_LITERAL));
  const char* repeated[] = { LOG_TEST_STRING_LITERAL, LOG_TEST_STRING_LITERAL };
  EXPECT_FALSE(file_contains_substrings_in_order(filename, repeated))
    << "log file " << filename << " appended rather than truncated";

  delete_file(filename);
  delete_file(archived_filename);
}
Beispiel #3
0
static void deletefiles_in_dir( const char* dirpath, dev_t device, time_t timestamp )
{
  DIR *dirp = opendir(dirpath);
  struct dirent *dp;

  if (dirp==NULL) {
    rotter_fatal( "Failed to open directory: %s.", dirpath );
    return;
  }

  // Check we are on the same device
  if (get_file_device(dirpath) != device) {
    rotter_debug( "Warning: %s isn't on same device as root dir.", dirpath );
    closedir( dirp );
    return;
  }

  // Check each item in the directory
  while( (dp = readdir( dirp )) != NULL ) {
    int newpath_len;
    char* newpath;

    if (strcmp( ".", dp->d_name )==0) continue;
    if (strcmp( "..", dp->d_name )==0) continue;


    newpath_len = strlen(dirpath) + strlen(dp->d_name) + 2;
    newpath = malloc( newpath_len );
    snprintf( newpath, newpath_len, "%s/%s", dirpath, dp->d_name );

    if (dp->d_type == DT_DIR) {

      // Process sub directory
      deletefiles_in_dir( newpath, device, timestamp );
      delete_file( newpath, device, timestamp );

    } else if (dp->d_type == DT_REG) {

      delete_file( newpath, device, timestamp );

    } else {
      rotter_error( "Warning: not a file or a directory: %s" );
    }
    free( newpath );

  }

  closedir( dirp );
}
Beispiel #4
0
static int
do_rm(void)
{
    int ret = -1;
    char name[MAX_FILE_NAME_LENGTH + 1];
    char *path;
    struct file *file;

    if (read_all(STDIN, name, MAX_FILE_NAME_LENGTH) != MAX_FILE_NAME_LENGTH)
        return -1;
    name[MAX_FILE_NAME_LENGTH] = '\0';

    if ((path = get_path_from_dir(&vfs, pwd)) == NULL)
        return -1;

    if ((path = append_to_path(path, name)) == NULL)
        goto free_path;

    if ((file = lookup_file(&vfs, path, 1)) == NULL)
        goto free_path;

    if (delete_file(&vfs, USER_UID, file) != 0)
        goto free_path;

    ret = 0;

free_path:
    free(path);
    return ret;
}
void IPC::clear()
{
	vector<string> file_name_vec = list_files_in_directory(ipc_path);
	for (string file_name_current : file_name_vec)
	{
		string file_name_everyone = "";
		if (file_name_current.size() >= 8)
			file_name_everyone = file_name_current.substr(0, 8);

		if (file_name_current.size() > self_name.size() || file_name_everyone == "everyone")
		{
			string file_name = "";
			string file_name_id_str = "";
			if (file_name_everyone != "everyone")
			{
				file_name = file_name_current.substr(0, self_name.size());
				file_name_id_str = file_name_current.substr(self_name.size(), file_name_current.size());
			}
			else
				continue;

			if (file_name == self_name || file_name_everyone == "everyone")
				delete_file(ipc_path + slash + file_name_current);
		}
	}
}
Beispiel #6
0
int main (int argc, char ** argv)
{
  
  open_FS();
  
  printf ("\nREPETOIRE AVANT :\n");
  list_dir ();
  printf ("FAT AVANT : ");
  list_fat ();
  
  printf ("\nEFFACER %s \n", argv[1]);
  if (delete_file (argv[1]) )
    printf ("%s n'existe pas \n", argv[1]);
  else
    { 
      printf ("\nREPETOIRE APRES :\n");
      list_dir ();
      printf ("FAT APRES : ");
      list_fat ();
    }
  
  close_FS ();

  return EXIT_SUCCESS;  
}
Beispiel #7
0
void replay_create_files(exe_file_system_t *exe_fs) {
  char tmpdir[PATH_MAX];
  unsigned k;

  if (!getcwd(tmpdir, PATH_MAX)) {
    perror("getcwd");
    exit(1);
  }

  strcat(tmpdir, ".temps");
  delete_file(tmpdir, 1);
  mkdir(tmpdir, 0755);  
  
  umask(0);
  for (k=0; k < exe_fs->n_sym_files; k++) {
    char name[2];
    sprintf(name, "%c", 'A' + k);
    create_file(-1, name, &exe_fs->sym_files[k], tmpdir);
  }

  if (exe_fs->sym_stdin)
    create_file(0, NULL, exe_fs->sym_stdin, tmpdir);

  if (exe_fs->sym_stdout)
    create_file(1, NULL, exe_fs->sym_stdout, tmpdir);

  if (exe_fs->sym_stdin)
    check_file(__STDIN, exe_fs->sym_stdin);

  if (exe_fs->sym_stdout)
    check_file(__STDOUT, exe_fs->sym_stdout);
  
  for (k=0; k<exe_fs->n_sym_files; ++k)
    check_file(k, &exe_fs->sym_files[k]);
}
Beispiel #8
0
void FeRomList::delete_emulator( const std::string & emu )
{
	//
	// Delete file
	//
	std::string path = m_config_path;
	path += FE_EMULATOR_SUBDIR;
	path += emu;
	path += FE_EMULATOR_FILE_EXTENSION;

	delete_file( path );

	//
	// Delete from our list if it has been loaded
	//
	for ( std::vector<FeEmulatorInfo>::iterator ite=m_emulators.begin();
			ite != m_emulators.end(); ++ite )
	{
		if ( emu.compare( (*ite).get_info( FeEmulatorInfo::Name ) ) == 0 )
		{
			m_emulators.erase( ite );
			break;
		}
	}
}
static void delete_status_bucket(struct cloudmig_ctx *ctx)
{
    dpl_status_t    dplret;
    dpl_vec_t       *objects = NULL;

    cloudmig_log(DEBUG_LVL, "[Deleting files]: Deleting status bucket...\n");

    dplret = dpl_list_bucket(ctx->src_ctx, ctx->status.bucket_name,
                             NULL, NULL, &objects, NULL);
    if (dplret != DPL_SUCCESS)
    {
        PRINTERR("%s: Could not list bucket %s for deletion : %s\n",
                 __FUNCTION__, ctx->status.bucket_name, dpl_status_str(dplret));
        goto deletebucket;
    }

    dpl_object_t** cur_object = (dpl_object_t**)objects->array;
    for (int i = 0; i < objects->n_items; ++i, ++cur_object)
        delete_file(ctx, ctx->status.bucket_name, (*cur_object)->key);

deletebucket:
    dpl_deletebucket(ctx->src_ctx, ctx->status.bucket_name);
    if (dplret != DPL_SUCCESS)
    {
        PRINTERR("%s: Could not delete bucket %s : %s.\n",
                 __FUNCTION__, ctx->status.bucket_name, dpl_status_str(dplret));
        return ;
    }
    cloudmig_log(DEBUG_LVL, "[Deleting Source] Bucket %s deleted.\n",
                 ctx->status.bucket_name);
}
Beispiel #10
0
TEST simple_concurrency() {
	delete_file();
	rliteContext *context1 = rliteConnect(FILEPATH, 0);
	rliteContext *context2 = rliteConnect(FILEPATH, 0);

	rliteReply* reply;
	size_t argvlen[100];

	{
		char* argv[100] = {"GET", "key", NULL};
		reply = rliteCommandArgv(context1, populateArgvlen(argv, argvlen), argv, argvlen);
		EXPECT_REPLY_NIL(reply);
		rliteFreeReplyObject(reply);
	}

	{
		char* argv[100] = {"set", "key", "value", NULL};
		reply = rliteCommandArgv(context2, populateArgvlen(argv, argvlen), argv, argvlen);
		EXPECT_REPLY_STATUS(reply, "OK", 2);
		rliteFreeReplyObject(reply);
	}
	{
		char* argv[100] = {"GET", "key", NULL};
		reply = rliteCommandArgv(context1, populateArgvlen(argv, argvlen), argv, argvlen);
		EXPECT_REPLY_STR(reply, "value", 5);
		rliteFreeReplyObject(reply);
	}

	rliteFree(context1);
	rliteFree(context2);
	unlink(FILEPATH);
	PASS();
}
Beispiel #11
0
void test_oss_media_hls_ossfile_handler_succeeded(CuTest *tc) {
    int ret;
    int64_t length;
    oss_media_hls_file_t *file;
    char *key = "test.txt";
    char *content = "hangzhou";

    file = oss_media_hls_open(TEST_BUCKET_NAME, key, auth_func);
    CuAssertTrue(tc, file != NULL);
    
    memcpy(&file->buffer->buf[file->buffer->pos], content, strlen(content));
    file->buffer->pos += strlen(content);

    CuAssertTrue(tc, file->buffer->pos != file->buffer->start);

    ret = oss_media_hls_ossfile_handler(file);
    CuAssertIntEquals(tc, 0, ret);

    CuAssertTrue(tc, file->buffer->pos == file->buffer->start);

    oss_media_hls_close(file);

    oss_media_file_t* read_file = oss_media_file_open(TEST_BUCKET_NAME, 
            key, "r", auth_func);
    CuAssertTrue(tc, read_file != NULL);

    uint8_t *buffer = (uint8_t*)malloc(strlen(content));
    length = oss_media_file_read(read_file, buffer, strlen(content));
    CuAssertIntEquals(tc, strlen(content), length);
    CuAssertStrnEquals(tc, content, strlen(content), (char*)buffer);

    free(buffer);
    delete_file(read_file);
    oss_media_file_close(read_file);
}
Beispiel #12
0
/*
 * Get file attributes.
 *
 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are ignored. The
 * 'st_ino' field is ignored except if the 'use_ino' mount option is given.
 */
int tagfs_getattr(const char *path, struct stat *statbuf) {
	char *file_location = NULL;
	int file_id = 0;
	int retstat = 0;

	DEBUG(ENTRY);
	INFO("Retrieving attributes for %s", path);

	if (valid_path_to_file(path)) {
		file_id = file_id_from_path(path);
		file_location = get_file_location(file_id);

		/* read information from actual file */
		retstat = stat(file_location, statbuf);

		if(retstat < 0) {
			WARN("Reading information from file %s failed", file_location);
			delete_file(file_id);
		}

		free_single_ptr((void **)&file_location);
	}
	else if(valid_path_to_folder(path)) {
		statbuf->st_mode = S_IFDIR | 0755; /* TODO: Set hard links, etc. */
	}
	else {
		retstat = -ENOENT;
	}

	DEBUG(EXIT);
	return retstat;
} /* tagfs_getattr */
void pending_operation_apply (struct pending_operation *P) {
  char full_oldpath[PATH_MAX], full_newpath[PATH_MAX];
  full_oldpath[0] = full_newpath[0] = 0;
  if (P->oldpath) {
    assert (snprintf (full_oldpath, PATH_MAX, "%s/%s", po_olddir, P->oldpath) < PATH_MAX);
  }
  if (P->newpath) {
    assert (snprintf (full_newpath, PATH_MAX, "%s/%s", po_newdir, P->newpath) < PATH_MAX);
  }
  switch (P->type) {
    case pot_null:
      kprintf ("pending_operation_apply (P.type == pot_null)\n");
      exit (1);
      break;
    case pot_mkdir:
      PO_ASSERT (mkdir (full_newpath, P->st.st_mode));
      PO_ASSERT (lcopy_attrs (full_newpath, &P->st));
      break;
    case pot_symlink:
      PO_ASSERT (symlink (P->oldpath, full_newpath));
      PO_ASSERT (lcopy_attrs (full_newpath, &P->st));
      break;
    case pot_rename:
      PO_ASSERT (rename (full_oldpath, full_newpath));
      PO_ASSERT (lcopy_attrs (full_newpath, &P->st));
      break;
    case pot_remove:
      PO_ASSERT (delete_file (full_newpath));
      break;
    case pot_copy_attrs:
      PO_ASSERT (lcopy_attrs (full_newpath, &P->st));
      break;
  }
}
Beispiel #14
0
} END_TEST

START_TEST(test_read_str) {
  // It should be ok
  char normal[] = "ab";
  wzfile file;
  create_file(&file, normal, strlen(normal));
  wzstr buffer;
  wz_init_str(&buffer);
  ck_assert_int_eq(wz_read_str(&buffer, strlen(normal), &file), 0);
  ck_assert_int_eq(memcmp(buffer.bytes, normal, strlen(normal)), 0);
  ck_assert(buffer.len == strlen(normal));
  ck_assert(memused() == sizeof(normal));

  // It should not change data if position + len > size
  wzstr copy = buffer;
  ck_assert_int_eq(wz_read_str(&buffer, strlen(normal), &file), 1);
  ck_assert(buffer.bytes == copy.bytes);
  ck_assert(buffer.len == copy.len);

  // It should not allocate memory if position + len > size
  ck_assert(memused() == sizeof(normal));
  wz_free_str(&buffer);
  delete_file(&file);
} END_TEST
Beispiel #15
0
} END_TEST

START_TEST(test_read_long) {
  // It should read positive int8
  char normal[] = "\x01\xfe\x80\x23\x45\x67\x89\xab\xcd\xef\01";
  wzfile file;
  create_file(&file, normal, strlen(normal));
  uint64_t buffer;
  ck_assert_int_eq(wz_read_long(&buffer, &file), 0);
  ck_assert(buffer == 1);

  // It should read negative int8
  ck_assert_int_eq(wz_read_long(&buffer, &file), 0);
  ck_assert(buffer == 0xfffffffffffffffe);

  // It should read postive int64
  ck_assert_int_eq(wz_read_long(&buffer, &file), 0);
  ck_assert(buffer == 0x01efcdab89674523);

  // It should not change data if position + len > size
  uint64_t copy = buffer;
  ck_assert_int_eq(wz_read_long(&buffer, &file), 1);
  ck_assert(buffer == copy);
  delete_file(&file);
} END_TEST
Beispiel #16
0
int
main(int argc, char **argv)
{
    /*int i;*/
    char db_dir[256];           /* the directory where the db file is */
    char dbfilename[256];       /* the database filename */
    char *filenames[1000];      /* the files to be added */
    char **fnames = filenames;
    short flag;                 /* flag for deleting or adding */

    parse_args(argv, db_dir, filenames, &flag);

    if (!filenames[0]) {
        fprintf(stderr, "%s\n", usage);
        return -1;
    }

    parser_init();

    build_db_filename(flag, db_dir, dbfilename);

    if (fresh)
        unlink(dbfilename);

    if (flag & Delete)
        while (*fnames)
            delete_file(dbfilename, *fnames++);
    else
        while (*fnames)
            add_file(dbfilename, *fnames++, fresh);
    return 0;
}
Beispiel #17
0
int main () {
  contenu txt;
    fifo * pf = creer_fifo () ;
    for (; ; ) {
          printf (" Ajouter un texte a la file (! pour retirer , * pour finir ) : ") ;
          saisir_contenu (& txt ) ;
          if ( comparer_chaine (& txt , "*") == 0)
               break ;
          if ( comparer_chaine (& txt , "!") == 0) {
               if ( est_vide_file ( pf ) ) {
                  printf (" Retrait imposible . File vide ") ;
               }
             else {
                 defiler_file ( pf , & txt ) ;
               }
               afficher_file ( pf ) ;
               printf ("\n ") ;
        }
          else {
            enfiler_file ( pf , & txt ) ;
               afficher_file ( pf ) ;
               printf ("\n ") ;
          }
    }

    delete_file ( pf ) ;
    getchar () ;
    return 0;
}
Beispiel #18
0
TEST threads_concurrency() {
	delete_file();
	rliteContext *context = rliteConnect(FILEPATH, 0);

	pthread_t thread;
	pthread_create(&thread, NULL, increment, NULL);

	rliteReply* reply;
	size_t argvlen[100];
	char* argv[100] = {"GET", "key", NULL};
	int argc = populateArgvlen(argv, argvlen);
	long long val;
	char tmp[40];

	do {
		reply = rliteCommandArgv(context, argc, argv, argvlen);
		if (reply->type == RLITE_REPLY_NIL) {
			val = 0;
		} else  if (reply->type != RLITE_REPLY_STRING) {
			fprintf(stderr, "Expected incremented value to be a string, got %d instead on line %d\n", reply->type, __LINE__);
			rliteFreeReplyObject(reply);
			break;
		} else {
			memcpy(tmp, reply->str, reply->len);
			tmp[reply->len] = 0;
			val = strtoll(tmp, NULL, 10);
		}
		rliteFreeReplyObject(reply);
	} while (val < INCREMENT_LIMIT);

	rliteFree(context);
	pthread_join(thread, NULL);
	PASS();
}
Beispiel #19
0
void FeRomList::save_favs()
{
	if (( !m_fav_changed ) || ( m_user_path.empty() ) || ( m_romlist_name.empty() ))
		return;

	//
	// First gather all the favourites from the current list into our extra favs list
	//
	for ( FeRomInfoListType::const_iterator itr = m_list.begin(); itr != m_list.end(); ++itr )
	{
		if ( !((*itr).get_info( FeRomInfo::Favourite ).empty()) )
			m_extra_favs.insert( (*itr).get_info( FeRomInfo::Romname ) );
	}

	//
	// Now save the contents of favs list
	//
	std::string fname = m_user_path + m_romlist_name + FE_FAVOURITE_FILE_EXTENSION;

	if ( m_extra_favs.empty() )
	{
		delete_file( fname );
	}
	else
	{
		std::ofstream outfile( fname.c_str() );
		if ( !outfile.is_open() )
			return;

		for ( std::set<std::string>::const_iterator itf = m_extra_favs.begin(); itf != m_extra_favs.end(); ++itf )
			outfile << (*itf) << std::endl;

		outfile.close();
	}
}
Beispiel #20
0
/* Note that we _must_ set the header information before we start recording!! */
void start_recording(
	void)
{
	FileDesc recording_file;
	long count;
	FileError error;
	
	assert(!replay.valid);
	replay.valid= TRUE;
	
	if(get_recording_filedesc(&recording_file))
	{
		delete_file(&recording_file);
	}

	error= create_file(&recording_file, FILM_FILE_TYPE);	
	if(!error)
	{
		/* I debate the validity of fsCurPerm here, but Alain had it, and it has been working */
		replay.recording_file_refnum= open_file_for_writing(&recording_file);
		if(replay.recording_file_refnum != NONE)
		{
			replay.game_is_being_recorded= TRUE;
	
			// save a header containing information about the game.
			count= sizeof(struct recording_header); 
			write_file(replay.recording_file_refnum, count, &replay.header);
		}
	}
}
Beispiel #21
0
static int delete_dir(const char *path, int recurse) {
  if (recurse) {
    DIR *d = opendir(path);
    struct dirent *de;

    if (d) {
      while ((de = readdir(d))) {
        if (strcmp(de->d_name, ".")!=0 && strcmp(de->d_name, "..")!=0) {
          char tmp[PATH_MAX];
          sprintf(tmp, "%s/%s", path, de->d_name);
          delete_file(tmp, 0);
        }
      }

      closedir(d);
    }
  }
 
  if (rmdir(path) == -1) {
    fprintf(stderr, "Cannot create file %s (exists, is dir, can't remove)\n", path);
    perror("rmdir");
    return -1;
  }

  return 0;
}
void test_read_file_succeeded(CuTest *tc) {
    int64_t write_size = 0;
    oss_media_file_t *file = NULL;
    char *write_content = NULL;
    char *read_content = NULL;
    int ntotal, nread, nbuf = 4;
    char buf[4];
    
    write_content = "hello oss media file\n";
    write_size = write_file(write_content);
    CuAssertTrue(tc, write_size != -1);

    // open file for read
    file = oss_media_file_open(TEST_BUCKET_NAME, "oss_media_file", "r", auth_func);
    CuAssertTrue(tc, NULL != file);

    // read file
    read_content = malloc(write_size + 1);
    ntotal = 0;
    while ((nread = oss_media_file_read(file, buf, nbuf)) > 0) {
        memcpy(read_content + ntotal, buf, nread);
        ntotal += nread;
    }
    read_content[ntotal] = '\0';    

    CuAssertIntEquals(tc, ntotal, strlen(read_content));
    CuAssertStrEquals(tc, write_content, read_content);

    // close file
    free(read_content);
    delete_file(file);
    oss_media_file_close(file);
}
Beispiel #23
0
void own_signal_handler(int a)
{
  if (verbose_mode > 1) printf("jpegoptim: signal: %d\n",a);
  if (outfile) fclose(outfile);
  if (outfname) if (file_exists(outfname)) delete_file(outfname);
  exit(1);
}
void test_read_file_failed_with_eof(CuTest *tc) {
    int64_t write_size = 0;
    oss_media_file_t *file = NULL;
    char *write_content = NULL;
    int nread, nbuf = 4;
    char buf[4];
    
    write_content = "hello oss media file\n";
    write_size = write_file(write_content);

    // open file for read
    file = oss_media_file_open(TEST_BUCKET_NAME, "oss_media_file", "r", auth_func);
    CuAssertTrue(tc, NULL != file);

    CuAssertIntEquals(tc, write_size - 1, oss_media_file_seek(file, write_size -1));
    CuAssertIntEquals(tc, write_size - 1, oss_media_file_tell(file));

    // read file
    nread = oss_media_file_read(file, buf, nbuf);
    CuAssertIntEquals(tc, 1, nread);

    nread = oss_media_file_read(file, buf, nbuf);
    CuAssertIntEquals(tc, 0, nread);

    CuAssertIntEquals(tc, -1, oss_media_file_seek(file, write_size + 1));
    CuAssertIntEquals(tc, write_size, oss_media_file_tell(file));

    // read file
    nread = oss_media_file_read(file, buf, nbuf);
    CuAssertIntEquals(tc, 0, nread);

    // close file
    delete_file(file);
    oss_media_file_close(file);
}
TEST_VM_F(LogConfigurationTest, output_name_normalization) {
  const char* patterns[] = { "%s", "file=%s", "\"%s\"", "file=\"%s\"" };
  char buf[1 * K];
  for (size_t i = 0; i < ARRAY_SIZE(patterns); i++) {
    int ret = jio_snprintf(buf, sizeof(buf), patterns[i], TestLogFileName);
    ASSERT_NE(-1, ret);
    set_log_config(buf, "logging=trace");
    EXPECT_TRUE(is_described("#2: "));
    EXPECT_TRUE(is_described(TestLogFileName));
    EXPECT_FALSE(is_described("#3: "))
        << "duplicate file output due to incorrect normalization for pattern: " << patterns[i];
  }

  // Make sure prefixes are ignored when used within quotes
  // (this should create a log with "file=" in its filename)
  int ret = jio_snprintf(buf, sizeof(buf), "\"file=%s\"", TestLogFileName);
  ASSERT_NE(-1, ret);
  set_log_config(buf, "logging=trace");
  EXPECT_TRUE(is_described("#3: ")) << "prefix within quotes not ignored as it should be";
  set_log_config(buf, "all=off");

  // Remove the extra log file created
  ret = jio_snprintf(buf, sizeof(buf), "file=%s", TestLogFileName);
  ASSERT_NE(-1, ret);
  delete_file(buf);
}
void test_seek_file_failed_with_file_not_exist(CuTest *tc) {
    int64_t write_size = 0;
    oss_media_file_t *file = NULL;
    char *write_content = NULL;
    oss_media_file_stat_t stat;
    int ret;
    
    write_content = "hello oss media file\n";
    write_size = write_file(write_content);

    // open file for read
    file = oss_media_file_open(TEST_BUCKET_NAME, "oss_media_file", "r", auth_func);
    CuAssertTrue(tc, NULL != file);

    file->object_key = "not_exist.key";

    // seek file
    ret = oss_media_file_seek(file, 1);
    CuAssertIntEquals(tc, -1, ret);

    // tell file
    ret = oss_media_file_tell(file);
    CuAssertIntEquals(tc, -1, ret);

    // stat file
    ret = oss_media_file_stat(file, &stat);
    CuAssertIntEquals(tc, -1, ret);

    // close file
    delete_file(file);
    oss_media_file_close(file);
}
void
st_close (st_parameter_close *clp)
{
  close_status status;
  gfc_unit *u;
#if !HAVE_UNLINK_OPEN_FILE
  char * path;

  path = NULL;
#endif

  library_start (&clp->common);

  status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED :
    find_option (&clp->common, clp->status, clp->status_len,
		 status_opt, "Bad STATUS parameter in CLOSE statement");

  if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK)
  {
    library_end ();
    return;
  }

  u = find_unit (clp->common.unit);
  if (u != NULL)
    {
      if (u->flags.status == STATUS_SCRATCH)
	{
	  if (status == CLOSE_KEEP)
	    generate_error (&clp->common, LIBERROR_BAD_OPTION,
			    "Can't KEEP a scratch file on CLOSE");
#if !HAVE_UNLINK_OPEN_FILE
	  path = (char *) gfc_alloca (u->file_len + 1);
          unpack_filename (path, u->file, u->file_len);
#endif
	}
      else
	{
	  if (status == CLOSE_DELETE)
            {
#if HAVE_UNLINK_OPEN_FILE
	      delete_file (u);
#else
	      path = (char *) gfc_alloca (u->file_len + 1);
              unpack_filename (path, u->file, u->file_len);
#endif
            }
	}

      close_unit (u);

#if !HAVE_UNLINK_OPEN_FILE
      if (path != NULL)
        unlink (path);
#endif
    }

  /* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */ 
  library_end ();
}
void test_append_file_succeeded(CuTest *tc) {
    int64_t write_size = 0;
    oss_media_file_t *file = NULL;
    char *content = NULL;
    oss_media_file_stat_t stat;
    int ret;

    content = "hello oss media file\n";

    // open file
    file = oss_media_file_open(TEST_BUCKET_NAME, "oss_media_file.txt", 
                               "a", auth_func);
    CuAssertTrue(tc, NULL != file);

    // write file
    write_size = oss_media_file_write(file, content, strlen(content));
    CuAssertIntEquals(tc, strlen(content), write_size);

    // write file
    write_size = oss_media_file_write(file, content, strlen(content));
    CuAssertIntEquals(tc, strlen(content), write_size);

    ret = oss_media_file_stat(file, &stat);
    CuAssertIntEquals(tc, 0, ret);

    CuAssertStrEquals(tc, "Appendable", stat.type);
    CuAssertIntEquals(tc, write_size * 2, stat.length);

    // close file
    delete_file(file);
    oss_media_file_close(file);
}
void IPC::send_message(string recipient, string message_head, string message_body, bool do_log)
{
	static int lock_file_count = 0;
	string lock_file_name = "lock_" + self_name + to_string(lock_file_count);
	write_string_to_file(ipc_path + slash + lock_file_name, "");
	++lock_file_count;

	vector<string> file_name_vec = list_files_in_directory(ipc_path);

	bool found = true;
	int file_count = 0;

	while (found)
	{
		found = false;
		for (string file_name_current : file_name_vec)
			if (file_name_current == recipient + to_string(file_count))
			{
				found = true;
				++file_count;
				break;
			}
	}

	static int sent_count = 0;

	string path_new = ipc_path + slash + recipient + to_string(file_count);
	write_string_to_file(path_new, message_head + "!" + message_body);

	++sent_count;
	delete_file(ipc_path + slash + lock_file_name);
	
	// if (do_log)
		// console_log("message sent: " + recipient + " " + message_head + " " + message_body, false);
}
Beispiel #30
0
/**
 * @brief admin_img the function to deal with admin reqeust for disk mode
 *
 * @param req the evhtp request
 * @param md5 the file md5
 * @param t admin type
 *
 * @return 1 for OK, 2 for 404 not found and -1 for fail
 */
int admin_img(evhtp_request_t *req, thr_arg_t *thr_arg, char *md5, int t)
{
    int result = -1;

    LOG_PRINT(LOG_DEBUG, "amdin_img() start processing admin request...");
    char whole_path[512];
    int lvl1 = str_hash(md5);
    int lvl2 = str_hash(md5 + 3);
    snprintf(whole_path, 512, "%s/%d/%d/%s", settings.img_path, lvl1, lvl2, md5);
    LOG_PRINT(LOG_DEBUG, "whole_path: %s", whole_path);

    if(is_dir(whole_path) == -1)
    {
        LOG_PRINT(LOG_DEBUG, "path: %s is not exist!", whole_path);
        return 2;
    }

    if(t == 1)
    {
        if(delete_file(whole_path) != -1)
        {
            result = 1;
            evbuffer_add_printf(req->buffer_out, 
                "<html><body><h1>Admin Command Successful!</h1> \
                <p>MD5: %s</p> \
                <p>Command Type: %d</p> \
                </body></html>",
                md5, t);
            evhtp_headers_add_header(req->headers_out, evhtp_header_new("Content-Type", "text/html", 0, 0));
        }
    }