mirror of
https://github.com/depp/syncfiles.git
synced 2024-05-28 23:41:27 +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);
|
memcpy(tname + 1 + pfxlen, ".tmp", 4);
|
||||||
tname[0] = pfxlen + 4;
|
tname[0] = pfxlen + 4;
|
||||||
err = FSMakeFSSpec(vRefNum, dirID, tname, temp);
|
err = FSMakeFSSpec(vRefNum, dirID, tname, temp);
|
||||||
if (err == 0) {
|
if (err != 0 && err != fnfErr) {
|
||||||
print_err("temporary file exists");
|
|
||||||
return 1;
|
|
||||||
} else if (err == fnfErr) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
print_errcode(err, "could not create temp file spec");
|
print_errcode(err, "could not create temp file spec");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the entire contents of a file.
|
// Write the entire contents of a file.
|
||||||
static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
|
static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
|
||||||
long length, long modTime, file_action action) {
|
long length, long modTime, file_action action) {
|
||||||
|
OSType creator = 'MPS ', fileType = 'TEXT';
|
||||||
FSSpec temp;
|
FSSpec temp;
|
||||||
long pos, amt;
|
long pos, amt;
|
||||||
short ref;
|
short ref;
|
||||||
|
@ -121,7 +118,15 @@ static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
return 1;
|
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) {
|
if (err != 0) {
|
||||||
print_errcode(err, "could not create file");
|
print_errcode(err, "could not create file");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user