Bug 1798459 - Move TruncFile to FileSystemWritableFileStream.cpp; r=dom-storage-reviewers,jesup

There are no other callers anymore.

Differential Revision: https://phabricator.services.mozilla.com/D161543
This commit is contained in:
Jan Varga
2022-11-09 17:15:37 +00:00
parent 98096acbf8
commit abfdaade13
3 changed files with 28 additions and 36 deletions

View File

@@ -80,6 +80,34 @@ class WritableFileStreamUnderlyingSinkAlgorithms final
RefPtr<FileSystemWritableFileStream> mStream;
};
/**
* TODO: Duplicated from netwerk/cache2/CacheFileIOManager.cpp
* Please remove after bug 1286601 is fixed,
* https://bugzilla.mozilla.org/show_bug.cgi?id=1286601
*/
nsresult TruncFile(PRFileDesc* aFD, int64_t aEOF) {
#if defined(XP_UNIX)
if (ftruncate(PR_FileDesc2NativeHandle(aFD), aEOF) != 0) {
NS_ERROR("ftruncate failed");
return NS_ERROR_FAILURE;
}
#elif defined(XP_WIN)
int64_t cnt = PR_Seek64(aFD, aEOF, PR_SEEK_SET);
if (cnt == -1) {
return NS_ERROR_FAILURE;
}
if (!SetEndOfFile((HANDLE)PR_FileDesc2NativeHandle(aFD))) {
NS_ERROR("SetEndOfFile failed");
return NS_ERROR_FAILURE;
}
#else
MOZ_ASSERT(false, "Not implemented!");
return NS_ERROR_NOT_IMPLEMENTED;
#endif
return NS_OK;
}
} // namespace
FileSystemWritableFileStream::FileSystemWritableFileStream(