mirror of
https://github.com/depp/syncfiles.git
synced 2024-06-08 18:29:30 +00:00
Only move and rename as necessary
GitOrigin-RevId: e3af6ccfdfa3fdb840b745afd225f270ea6c4070
This commit is contained in:
parent
ff6149d125
commit
a13293fc92
44
file.c
44
file.c
|
@ -112,6 +112,7 @@ static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
|
||||||
Str31 name;
|
Str31 name;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
int r;
|
int r;
|
||||||
|
bool mustMove, mustRename;
|
||||||
|
|
||||||
// Save the data to a temporary file.
|
// Save the data to a temporary file.
|
||||||
r = make_temp(&temp, tempVol, tempDir, dest->name);
|
r = make_temp(&temp, tempVol, tempDir, dest->name);
|
||||||
|
@ -202,28 +203,33 @@ static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mustMove = dest->parID != temp.parID;
|
||||||
|
mustRename = memcmp(dest->name, temp.name, dest->name[0] + 1) != 0;
|
||||||
|
|
||||||
// Next, try MoveRename.
|
// Next, try MoveRename.
|
||||||
memset(&pb, 0, sizeof(pb));
|
if (mustMove && mustRename) {
|
||||||
pb.copyParam.ioNamePtr = temp.name;
|
memset(&pb, 0, sizeof(pb));
|
||||||
pb.copyParam.ioVRefNum = temp.vRefNum;
|
pb.copyParam.ioNamePtr = temp.name;
|
||||||
pb.copyParam.ioNewName = dest->name;
|
pb.copyParam.ioVRefNum = temp.vRefNum;
|
||||||
pb.copyParam.ioNewDirID = dest->parID;
|
pb.copyParam.ioNewName = dest->name;
|
||||||
pb.copyParam.ioDirID = temp.parID;
|
pb.copyParam.ioNewDirID = dest->parID;
|
||||||
err = PBHMoveRenameSync(&pb);
|
pb.copyParam.ioDirID = temp.parID;
|
||||||
if (gLogLevel >= kLogVerbose) {
|
err = PBHMoveRenameSync(&pb);
|
||||||
log_call(err, "PBHMoveRename");
|
if (gLogLevel >= kLogVerbose) {
|
||||||
}
|
log_call(err, "PBHMoveRename");
|
||||||
if (err == 0) {
|
}
|
||||||
return 0;
|
if (err == 0) {
|
||||||
}
|
return 0;
|
||||||
// paramErr: function not supported by volume.
|
}
|
||||||
if (err != paramErr) {
|
// paramErr: function not supported by volume.
|
||||||
print_errcode(err, "could not rename temporary file");
|
if (err != paramErr) {
|
||||||
goto error;
|
print_errcode(err, "could not rename temporary file");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, try move and then rename.
|
// Finally, try move and then rename.
|
||||||
if (dest->parID != temp.parID) {
|
if (mustMove) {
|
||||||
memset(&cm, 0, sizeof(cm));
|
memset(&cm, 0, sizeof(cm));
|
||||||
cm.ioNamePtr = temp.name;
|
cm.ioNamePtr = temp.name;
|
||||||
cm.ioVRefNum = temp.vRefNum;
|
cm.ioVRefNum = temp.vRefNum;
|
||||||
|
@ -239,7 +245,7 @@ static int write_file(FSSpec *dest, short tempVol, long tempDir, Ptr data,
|
||||||
}
|
}
|
||||||
temp.parID = dest->parID;
|
temp.parID = dest->parID;
|
||||||
}
|
}
|
||||||
if (memcmp(dest->name, temp.name, dest->name[0] + 1) != 0) {
|
if (mustRename) {
|
||||||
err = FSpRename(&temp, dest->name);
|
err = FSpRename(&temp, dest->name);
|
||||||
if (gLogLevel >= kLogVerbose) {
|
if (gLogLevel >= kLogVerbose) {
|
||||||
log_call(err, "FSpRename");
|
log_call(err, "FSpRename");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user