mirror of
https://github.com/vgough/encfs.git
synced 2024-11-22 16:03:34 +01:00
try to maintain atime/mtime during rename. patch by p.kosseff
git-svn-id: http://encfs.googlecode.com/svn/trunk@48 db9cf616-1c43-0410-9cb8-a902689de0d6
This commit is contained in:
parent
5b33fb7b3b
commit
f6c5f0440a
@ -226,6 +226,9 @@ bool RenameOp::apply()
|
|||||||
rDebug("renaming %s -> %s",
|
rDebug("renaming %s -> %s",
|
||||||
last->oldCName.c_str(), last->newCName.c_str());
|
last->oldCName.c_str(), last->newCName.c_str());
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
bool preserve_mtime = ::stat(last->oldCName.c_str(), &st) == 0;
|
||||||
|
|
||||||
// internal node rename..
|
// internal node rename..
|
||||||
dn->renameNode( last->oldPName.c_str(),
|
dn->renameNode( last->oldPName.c_str(),
|
||||||
last->newPName.c_str() );
|
last->newPName.c_str() );
|
||||||
@ -241,6 +244,14 @@ bool RenameOp::apply()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(preserve_mtime)
|
||||||
|
{
|
||||||
|
struct utimbuf ut;
|
||||||
|
ut.actime = st.st_atime;
|
||||||
|
ut.modtime = st.st_mtime;
|
||||||
|
::utime(last->newCName.c_str(), &ut);
|
||||||
|
}
|
||||||
|
|
||||||
++last;
|
++last;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,6 +633,9 @@ DirNode::rename( const char *fromPlaintext, const char *toPlaintext )
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
struct stat st;
|
||||||
|
bool preserve_mtime = ::stat(fromCName.c_str(), &st) == 0;
|
||||||
|
|
||||||
renameNode( fromPlaintext, toPlaintext );
|
renameNode( fromPlaintext, toPlaintext );
|
||||||
res = ::rename( fromCName.c_str(), toCName.c_str() );
|
res = ::rename( fromCName.c_str(), toCName.c_str() );
|
||||||
|
|
||||||
@ -633,6 +647,12 @@ DirNode::rename( const char *fromPlaintext, const char *toPlaintext )
|
|||||||
|
|
||||||
if(renameOp)
|
if(renameOp)
|
||||||
renameOp->undo();
|
renameOp->undo();
|
||||||
|
} else if(preserve_mtime)
|
||||||
|
{
|
||||||
|
struct utimbuf ut;
|
||||||
|
ut.actime = st.st_atime;
|
||||||
|
ut.modtime = st.st_mtime;
|
||||||
|
::utime(toCName.c_str(), &ut);
|
||||||
}
|
}
|
||||||
} catch( rlog::Error &err )
|
} catch( rlog::Error &err )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user