mirror of
https://github.com/depp/syncfiles.git
synced 2025-01-08 20:35:00 +00:00
Handle case where temporary file exists
GitOrigin-RevId: 029ce369a00c5f18bc50174eb4fde677b4984f1b
This commit is contained in:
parent
4e0d9b16c7
commit
ff6149d125
19
file.c
19
file.c
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user