cellSaveData: restore atime/mtime for unmodified files

This commit is contained in:
Nekotekina 2018-11-16 14:35:52 +03:00
parent 1fdd013e4b
commit 12ceceff19

View file

@ -673,6 +673,7 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
} }
// Enter the loop where the save files are read/created/deleted // Enter the loop where the save files are read/created/deleted
std::map<std::string, std::pair<s64, s64>> all_times;
std::map<std::string, fs::file> all_files; std::map<std::string, fs::file> all_files;
// First, preload all files (TODO: beware of possible lag, although it should be insignificant) // First, preload all files (TODO: beware of possible lag, although it should be insignificant)
@ -681,6 +682,7 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
if (!entry.is_directory) if (!entry.is_directory)
{ {
// Read file into a vector and make a memory file // Read file into a vector and make a memory file
all_times.emplace(entry.name, std::make_pair(entry.atime, entry.mtime));
all_files.emplace(std::move(entry.name), fs::make_stream(fs::file(dir_path + entry.name).to_vector<uchar>())); all_files.emplace(std::move(entry.name), fs::make_stream(fs::file(dir_path + entry.name).to_vector<uchar>()));
} }
} }
@ -815,6 +817,7 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
const u64 wr = file.write(fileSet->fileBuf.get_ptr(), access_size); const u64 wr = file.write(fileSet->fileBuf.get_ptr(), access_size);
file.trunc(wr); file.trunc(wr);
fileGet->excSize = ::narrow<u32>(wr); fileGet->excSize = ::narrow<u32>(wr);
all_times.erase(file_path);
has_modified = true; has_modified = true;
break; break;
} }
@ -825,6 +828,7 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
all_files[file_path].close(); all_files[file_path].close();
psf.erase("*" + file_path); psf.erase("*" + file_path);
fileGet->excSize = 0; fileGet->excSize = 0;
all_times.erase(file_path);
has_modified = true; has_modified = true;
break; break;
} }
@ -842,6 +846,7 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
const u64 sr = file.seek(fileSet->fileOffset); const u64 sr = file.seek(fileSet->fileOffset);
const u64 wr = file.write(fileSet->fileBuf.get_ptr(), access_size); const u64 wr = file.write(fileSet->fileBuf.get_ptr(), access_size);
fileGet->excSize = ::narrow<u32>(wr); fileGet->excSize = ::narrow<u32>(wr);
all_times.erase(file_path);
has_modified = true; has_modified = true;
break; break;
} }
@ -881,6 +886,12 @@ static NEVER_INLINE s32 savedata_op(ppu_thread& ppu, u32 operation, u32 version,
} }
} }
for (auto&& pair : all_times)
{
// Restore atime/mtime for files which have not been modified
fs::utime(new_path + pair.first, pair.second.first, pair.second.second);
}
// Remove old backup // Remove old backup
fs::remove_all(old_path, false); fs::remove_all(old_path, false);