Skip to content

Commit

Permalink
Require backup dir in backup function
Browse files Browse the repository at this point in the history
  • Loading branch information
onovy committed Apr 17, 2017
1 parent 2516f1d commit 030f80a
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions Todos.php
Expand Up @@ -284,37 +284,35 @@ public function searchSimilar($todo) {
public static function backup($todoFile, $backupDir) {
clearstatcache();

if ($backupDir) {
$c = 0;
do {
$target =
'todo.' . date('c') . '-' . str_pad($c, 2, '0', STR_PAD_LEFT) . '.txt';
$targetA =
$backupDir .
DIRECTORY_SEPARATOR .
$target;
$c++;
} while (file_exists($targetA));
$last =
$c = 0;
do {
$target =
'todo.' . date('c') . '-' . str_pad($c, 2, '0', STR_PAD_LEFT) . '.txt';
$targetA =
$backupDir .
DIRECTORY_SEPARATOR .
'todo.last.txt';
if (file_exists($last)) {
$cLast = file($last);
$cSource = file($todoFile);
sort($cLast);
sort($cSource);
if (implode("\n", $cLast) === implode("\n", $cSource)) {
return;
}
$target;
$c++;
} while (file_exists($targetA));
$last =
$backupDir .
DIRECTORY_SEPARATOR .
'todo.last.txt';
if (file_exists($last)) {
$cLast = file($last);
$cSource = file($todoFile);
sort($cLast);
sort($cSource);
if (implode("\n", $cLast) === implode("\n", $cSource)) {
return;
}
@mkdir($backupDir, 0700, true);
copy(
$todoFile,
$targetA
);
@unlink($last);
symlink($target, $last);
}
@mkdir($backupDir, 0700, true);
copy(
$todoFile,
$targetA
);
@unlink($last);
symlink($target, $last);
}
}

0 comments on commit 030f80a

Please sign in to comment.