Cache-FastMmap

 view release on metacpan or  search on metacpan

t/20.t  view on Meta::CPAN

}

require_ok('Cache::FastMmap');

my $old_umask = umask 0000;
note( 'umask returns undef on this system, test results may not be reliable')
    unless defined $old_umask;

my $FC = Cache::FastMmap->new(init_file => 1);
ok( defined $FC );
my (undef, undef, $Mode) = stat($FC->{share_file});
$Mode = $Mode & 0777;
is($Mode, 0640, "default persmissions 0640");
undef $FC;

my $FC = Cache::FastMmap->new(init_file => 1, permissions => 0600);
ok( defined $FC );
my (undef, undef, $Mode) = stat($FC->{share_file});
$Mode = $Mode & 0777;
is($Mode, 0600, "can set to 0600");
undef $FC;

my $FC = Cache::FastMmap->new(init_file => 1, permissions => 0666);
ok( defined $FC );
my (undef, undef, $Mode) = stat($FC->{share_file});
$Mode = $Mode & 0777;
is($Mode, 0666, "can set to 0666");
undef $FC;

unix.c  view on Meta::CPAN

{
  return def_share_file;
}

int mmc_open_cache_file(mmap_cache* cache, int * do_init) {
  int res, i, fh;
  void * tmp;
  struct stat statbuf;

  /* Check if file exists */
  res = stat(cache->share_file, &statbuf);

  /* Remove if different size or remove requested */
  if (!res &&
      (cache->init_file || (statbuf.st_size != cache->c_size))) {
    res = remove(cache->share_file);
    if (res == -1 && errno != ENOENT) {
      return _mmc_set_error(cache, errno, "Unlink of existing share file %s failed", cache->share_file);
    }
  }

  /* Create file if it doesn't exist */
  *do_init = 0;
  res = stat(cache->share_file, &statbuf);
  if (res == -1) {
    mode_t permissions = (mode_t)cache->permissions;
    res = open(cache->share_file, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC | O_APPEND, permissions);
    if (res == -1) {
      return _mmc_set_error(cache, errno, "Create of share file %s failed", cache->share_file);
    }

    /* Fill file with 0's */
    tmp = calloc(1, cache->c_page_size);
    if (!tmp) {



( run in 0.588 second using v1.01-cache-2.11-cpan-49f99fa48dc )