IET-OU/open-media-player

View on GitHub
application/bin/cpn

Summary

Maintainability
Test Coverage
#!/usr/bin/env php
<?php
namespace IET_OU\Open_Media_Player_Tools;

/**
 * A cross-platform "copy-no-clobber" utility (equivalent to Linux "cp -n")
 *
 * @author Nick Freear, 10 July 2015.
 */

$dir = '';
if ($argc < 3) {
    fprintf(STDERR, "Error, insufficient arguments. Expecting:\n\t\$ cpn working_directory source destination\nOR\n\t\$ cpn source destination\n");
    exit(1);
}
if (3 == $argc) {
    $source = $dir . $argv[ 1 ];
    $dest = $dir . $argv[ 2 ];
}
elseif ($argc > 3) {
    $dir = rtrim($argv[ $argc - 3 ], '/') . '/';

    $source = $dir . $argv[ $argc - 2 ];
    $dest = $dir . $argv[ $argc - 1 ];
}

fprintf(STDERR, "copy-no-clobber: $source $dest\n");

if (file_exists($dest)) {
    fprintf(STDERR, "Warning: file '$dest' already exists. Stopping.\n");
    exit(0);
}

$bok = copy($source, $dest );

fprintf(STDERR, "copy-no-clobber. Exit: %d\n", ! $bok);
exit((int) ! $bok);


//End.


// =========================================================

/* cpn.bat

@ECHO OFF
SET BIN_TARGET=%~dp0/cpn
php "%BIN_TARGET%" %*

*/