App-Nrepo

 view release on metacpan or  search on metacpan

lib/App/Nrepo/Plugin/Yum.pm  view on Meta::CPAN


  }

  $self->init_arch($arch);

}

sub del_file {
  my $self  = shift;
  my $arch  = shift;
  my $files = shift;

  unless ( $self->validate_arch($arch) ) {
    $self->logger->log_and_croak(
      level   => 'error',
      message => sprintf 'del_file: arch: %s is not in config for repo: %s',
      $arch, $self->repo()
    );
  }

  for my $file ( @${files} ) {
    my $filename = basename($file);
    my $dest_file =
      File::Spec->catfile( $self->dir(), $arch, $self->packages_dir(),
      $filename );
    $self->logger->debug( sprintf 'del_file: repo: %s arch: %s dest_file: %s',
      $self->repo(), $arch, $dest_file );

    unless ( -f $dest_file ) {
      $self->logger->log_and_croak(
        level   => 'error',
        message => sprintf 'del_file: repo: %s dest_file: %s does not exist',
        $self->repo(), $dest_file
      );
    }

    unlink $dest_file || $self->logger->log_and_croak(
      level   => 'error',
      message => sprintf
        'del_file: repo: %s failed to del file: %s from destination: %s',
      $self->repo(), $dest_file, $!
    );

  }

  $self->init_arch($arch);
}

sub init_arch {
  my $self = shift;
  my $arch = shift;

  my $dir = File::Spec->catdir( $self->dir, $arch );

  $self->logger->debug( sprintf 'init_arch: repo: %s arch: %s dir: %s',
    $self->repo(), $arch, $dir );

  $self->make_dir($dir);
  $self->make_dir( File::Spec->catdir( $dir, $self->packages_dir() ) );

  #XXX add gpg

  #TODO perhaps replace createrepo with pure perl version at some stage
  my $createrepo_bin = $self->find_command_path('createrepo');

  unless ( $createrepo_bin and -x $createrepo_bin ) {
    $self->logger->log_and_croak(
      level   => 'error',
      message => sprintf(
        'init_arch: repo: %s arch: %s unable to find createrepo program in path',
        $self->repo(), $arch
      ),
    );
  }

  my @cmd = (
    $createrepo_bin, '--basedir', $dir, '--outputdir', $dir,
    $self->packages_dir()
  );

# --update will reuse the existing metadata if the file is already defined and size/mtime matches
# dont do this if we're forcing or the repomd.xml doesnt exist
  unless ( $self->force() ) {
    if ( -f File::Spec->catfile( $dir, $self->repodata_dir(), 'repomd.xml' ) ) {
      splice @cmd, 1, 0, '--update';
    }
  }

  $self->logger->debug( sprintf 'init_arch: running command: %s',
    join( ' ', @cmd ) );
  unless ( system(@cmd) == 0 ) {
    $self->logger->log_and_croak(
      level   => 'error',
      message => sprintf(
        'init_arch: repo: %s failed to run command: %s with exit code: %s',
        $self->repo(), join( ' ', @cmd ), $?,
      )
    );
  }

}

sub type {

  #my $self = shift;
  return 'Yum';
}

1;



( run in 0.729 second using v1.01-cache-2.11-cpan-e1769b4cff6 )