#! /usr/bin/perl use FileMirror; use Test; use Data::Dumper; BEGIN { plan tests => 6 } my $fm = FileMirror->new( '/tmp', '/new/tmp' ); ok('/new/tmp/x', $fm->dest_from_source('/tmp/x'), 'Unix dest_from_source' ); $fm = FileMirror->new( 'C:\tmp', 'D:\tmp' ); ok('D:\tmp\x', $fm->dest_from_source('C:\tmp\x'), 'DOS dest_from_source' ); system('touch /tmp/foo'); mkdir('/tmp/new'); $fm = FileMirror->new( '/tmp', '/tmp/new' ); $fm->copy('/tmp/foo'); ok( -e '/tmp/new/foo', 1, 'copying' ); unlink '/tmp/foo'; unlink '/tmp/new/foo'; rmdir '/tmp/new'; # test moving system('touch /tmp/foo'); mkdir('/tmp/new'); $fm = FileMirror->new( '/tmp', '/tmp/new' ); $fm->move('/tmp/foo'); ok( -e '/tmp/new/foo' && ! -e '/tmp/foo', 1, 'moving' ); unlink '/tmp/new/foo'; rmdir '/tmp/new'; # test safety of deletion. if the file vanishes from destination # then we don't delete. system('touch /tmp/foo'); mkdir('/tmp/new'); $fm = FileMirror->new( '/tmp', '/tmp/new' ); $fm->copy('/tmp/foo'); # remove the copy unlink '/tmp/new/foo'; $fm->delete_original('/tmp/foo'); # the original should be unchanged ok( -e '/tmp/foo', 1, 'delete_original after deleting copy' ); unlink '/tmp/foo'; rmdir '/tmp/new'; # test safety of deletion. # if the file size changes, don't delete. system('touch /tmp/foo'); mkdir('/tmp/new'); $fm = FileMirror->new( '/tmp', '/tmp/new' ); $fm->copy('/tmp/foo'); # alter the copy, changing its size system('echo abcdefg > /tmp/new/foo'); $fm->delete_original('/tmp/foo'); # the original should be unchanged ok( -e '/tmp/foo', 1, 'delete_original after modifying copy' ); unlink '/tmp/foo'; unlink '/tmp/new/foo'; rmdir '/tmp/new';