Handle case where temporary file exists

GitOrigin-RevId: 029ce369a00c5f18bc50174eb4fde677b4984f1b
This commit is contained in:
Dietrich Epp 2021-03-16 12:24:56 -04:00
parent 4e0d9b16c7
commit ff6149d125
1 changed files with 12 additions and 7 deletions

19
file.c
View File

@ -92,20 +92,17 @@ static int make_temp(FSSpec *temp, short vRefNum, long dirID,
memcpy(tname + 1 + pfxlen, ".tmp", 4);
tname[0] = pfxlen + 4;
err = FSMakeFSSpec(vRefNum, dirID, tname, temp);
if (err == 0) {
print_err("temporary file exists");
return 1;
} else if (err == fnfErr) {
return 0;
} else {
if (err != 0 && err != fnfErr) {
print_errcode(err, "could not create temp file spec");
return 1;
}
return 0;
}
// Write the entire contents of a file.
static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
long length, long modTime, file_action action) {
OSType creator = 'MPS ', fileType = 'TEXT';
FSSpec temp;
long pos, amt;
short ref;
@ -121,7 +118,15 @@ static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
if (r != 0) {
return 1;
}
err = FSpCreate(&temp, 'MPS ', 'TEXT', smSystemScript);
err = FSpCreate(&temp, creator, fileType, smSystemScript);
if (err == dupFNErr) {
err = FSpDelete(&temp);
if (err != 0) {
print_errcode(err, "could not delete existing temp file");
return 1;
}
err = FSpCreate(&temp, creator, fileType, smSystemScript);
}
if (err != 0) {
print_errcode(err, "could not create file");
return 1;