Skip to content
Snippets Groups Projects
Commit 706d5dd1 authored by deuce's avatar deuce
Browse files

Add correct handling for Replaces line.

If Replaces is the same as the new filename, replace it.  Otherwise, return
and error and process the next TIC file.
parent c75b081e
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@
*/
load("sbbsdefs.js");
load("fido.js");
load("fidocfg.js");
var sbbsecho = new SBBSEchoCfg();
......@@ -74,6 +75,48 @@ if (!String.prototype.repeat) {
};
}
/*
* TODO: Copied from binkit.js
*/
function rename_or_move(src, dst)
{
var sf;
var df;
var buf;
var remain;
if (file_rename(src, dst))
return true;
sf = new File(src);
if (!sf.open("rb"))
return false;
df = new File(dst);
if (!df.open("web")) {
sf.close();
return false;
}
while (!sf.eof) {
// Read 2MB at a time...
remain = sf.length - sf.position;
if (remain === 0)
break;
if (remain > 0x200000)
remain = 0x200000;
buf = sf.read(remain);
if (!df.write(buf)) {
df.close();
df.remove();
sf.close();
return false;
}
}
df.close();
sf.close();
df.date = sf.date;
sf.remove();
return true;
}
function process_tic(tic)
{
var dir;
......@@ -123,12 +166,28 @@ function process_tic(tic)
}
}
function do_move(path, tic) {
if (rename_or_move(tic.full_path, path+tic.file))
tic.full_path = path+tic.file;
else {
log(LOG_ERROR, "Cannot move '"+tic.full_path+"' to '"+path+tic.file+"'!");
return false;
}
return true;
}
log(LOG_DEBUG, "Moving file from "+tic.full_path+" to "+path+".");
if (file_rename(tic.full_path, path+tic.file))
tic.full_path = path+tic.file;
if (file_exists(path+tic.file)) {
if (tic.file !== tic.replaces)
log(LOG_ERROR, "'"+tic.full_path+"' already exists in '"+path+"' and TIC does not have Replaces line.");
else {
if (!do_move(path, tic))
return false;
}
}
else {
log(LOG_ERROR, "Cannot move '"+tic.full_path+"' to '"+path+tic.file+"'!");
return false;
if (!do_move(path, tic))
return false;
}
if (dir !== undefined) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment