summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-05-21 12:30:21 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-22 14:00:31 +0200
commit1d58828f2285064635ed776e0641e83ee26d34da (patch)
treed8bbb109092bcc9654441d094af2ec5a852be7d6 /sal
parent671e755aef9c4019bdca2fbbe5e5e6c704954a32 (diff)
[API CHANGE] call ftruncate instead of ftruncate_by_name
The actual point of this change is making osl_fileOpen faster by avoiding constructing and storing an OString. But that requires changing to using ftruncate on the filehandle, which is arguably more correct anyway, using the filename to truncate in the presence of unlink() is dubious Change-Id: I8bc5022e1d1afb53fb4e2fd920e43e5daaf74ec4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134704 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/file.cxx47
-rw-r--r--sal/osl/unx/file_impl.hxx2
2 files changed, 23 insertions, 26 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index cbf6e4fa57b6..351d1457e89b 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -82,7 +82,6 @@ namespace {
struct FileHandle_Impl
{
pthread_mutex_t m_mutex;
- OString m_strFilePath; /*< holds native file path */
int m_fd;
enum Kind
@@ -109,7 +108,7 @@ struct FileHandle_Impl
rtl_String* m_memstreambuf; /*< used for in-memory streams */
#endif
- explicit FileHandle_Impl(int fd, Kind kind = KIND_FD, OString path = "<anon>");
+ explicit FileHandle_Impl(int fd, Kind kind = KIND_FD);
~FileHandle_Impl();
static void* operator new (size_t n);
@@ -185,9 +184,8 @@ FileHandle_Impl::Guard::~Guard()
(void) pthread_mutex_unlock(m_mutex);
}
-FileHandle_Impl::FileHandle_Impl(int fd, enum Kind kind, OString path)
- : m_strFilePath(std::move(path)),
- m_fd (fd),
+FileHandle_Impl::FileHandle_Impl(int fd, enum Kind kind)
+ : m_fd (fd),
m_kind (kind),
m_state (State::Seekable | State::Readable),
m_size (0),
@@ -257,7 +255,7 @@ sal_uInt64 FileHandle_Impl::getSize() const
oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize)
{
off_t const nSize = sal::static_int_cast< off_t >(uSize);
- if (ftruncate_with_name(m_fd, nSize, m_strFilePath) == -1)
+ if (ftruncate(m_fd, nSize) == -1)
{
/* Failure. Save original result. Try fallback algorithm */
oslFileError result = oslTranslateFileError(errno);
@@ -745,12 +743,12 @@ oslFileHandle osl::detail::createFileHandleFromFD(int fd)
pImpl->m_size = sal::static_int_cast< sal_uInt64 >(aFileStat.st_size);
}
- SAL_INFO("sal.file", "osl::detail::createFileHandleFromFD(" << pImpl->m_fd << ", writeable) => " << pImpl->m_strFilePath);
+ SAL_INFO("sal.file", "osl::detail::createFileHandleFromFD(" << pImpl->m_fd << ", writeable)");
return static_cast<oslFileHandle>(pImpl);
}
-static int osl_file_adjustLockFlags(const OString& path, int flags)
+static int osl_file_adjustLockFlags(const char* cpPath, int flags)
{
#ifdef MACOSX
/*
@@ -761,7 +759,7 @@ static int osl_file_adjustLockFlags(const OString& path, int flags)
* for the filesystem name.
*/
struct statfs s;
- if(statfs(path.getStr(), &s) >= 0)
+ if(statfs(cpPath, &s) >= 0)
{
if(strncmp("afpfs", s.f_fstypename, 5) == 0)
{
@@ -775,7 +773,7 @@ static int osl_file_adjustLockFlags(const OString& path, int flags)
}
}
#else
- (void) path;
+ (void) cpPath;
#endif
return flags;
@@ -811,13 +809,12 @@ static bool osl_file_queryLocking(sal_uInt32 uFlags)
namespace {
static oslFileError openMemoryAsFile(const OString &rData,
- oslFileHandle *pHandle,
- const OString& path)
+ oslFileHandle *pHandle)
{
const char *address = rData.getStr();
size_t size = rData.getLength();
- FileHandle_Impl *pImpl = new FileHandle_Impl(-1, FileHandle_Impl::KIND_MEM, path);
+ FileHandle_Impl *pImpl = new FileHandle_Impl(-1, FileHandle_Impl::KIND_MEM);
pImpl->m_size = sal::static_int_cast< sal_uInt64 >(size);
*pHandle = (oslFileHandle)(pImpl);
@@ -887,7 +884,7 @@ private:
#endif
-oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
+oslFileError openFilePath(const char* cpFilePath, oslFileHandle* pHandle,
sal_uInt32 uFlags, mode_t mode)
{
oslFileError eRet;
@@ -896,16 +893,16 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
/* Opening a file from /assets read-only means
* we should mmap it from the .apk file
*/
- if (o3tl::starts_with(filePath, "/assets/"))
+ if (o3tl::starts_with(cpFilePath, "/assets/"))
{
OString aData;
bool bCache = true;
- const char *cpAssetsPath = filePath.getStr() + sizeof("/assets/") - 1;
+ const char *cpAssetsPath = cpFilePath + sizeof("/assets/") - 1;
// some requests are /assets//foo...
if (cpAssetsPath[0] == '/')
{
- __android_log_print(ANDROID_LOG_DEBUG,"libo:sal/osl/unx/file", "double-slash in path: %s", filePath.getStr());
+ __android_log_print(ANDROID_LOG_DEBUG,"libo:sal/osl/unx/file", "double-slash in path: %s", cpFilePath);
cpAssetsPath++;
}
@@ -920,7 +917,7 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
if (pMiss)
{
errno = ENOENT;
- __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "miss cache: failed to open %s", filePath.getStr());
+ __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "miss cache: failed to open %s", cpFilePath);
return osl_File_E_NOENT;
}
AAssetManager* mgr = lo_get_native_assetmgr();
@@ -929,7 +926,7 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
{
AndroidFileCache::getMissCache().insert(cpAssetsPath, aData);
errno = ENOENT;
- __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open %s", filePath.getStr());
+ __android_log_print(ANDROID_LOG_ERROR,"libo:sal/osl/unx/file", "failed to open %s", cpFilePath);
return osl_File_E_NOENT;
}
else
@@ -955,9 +952,9 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
// loading a document from /assets fails with that idiotic
// "General Error" dialog...
}
- SAL_INFO("sal.file", "osl_openFile(" << filePath << ") => '" << cpAssetsPath << "'"
+ SAL_INFO("sal.file", "osl_openFile(" << cpFilePath << ") => '" << cpAssetsPath << "'"
<< aData.getLength() << " bytes from file " << (bCache ? "cache" : "system"));
- return openMemoryAsFile(aData, pHandle, filePath);
+ return openMemoryAsFile(aData, pHandle);
}
#endif
@@ -995,7 +992,7 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
}
else
{
- flags = osl_file_adjustLockFlags (filePath, flags);
+ flags = osl_file_adjustLockFlags (cpFilePath, flags);
}
// O_EXCL can be set only when O_CREAT is set
@@ -1003,7 +1000,7 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
flags &= ~O_EXCL;
/* open the file */
- int fd = open_c( filePath, flags, mode );
+ int fd = open_c( cpFilePath, flags, mode );
if (fd == -1)
{
return oslTranslateFileError(errno);
@@ -1057,7 +1054,7 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
if (!S_ISREG(aFileStat.st_mode))
{
/* we only open regular files here */
- SAL_INFO("sal.file", "osl_openFile(" << filePath << "): not a regular file");
+ SAL_INFO("sal.file", "osl_openFile(" << cpFilePath << "): not a regular file");
(void) close(fd);
SAL_INFO("sal.file", "close(" << fd << ")");
return osl_File_E_INVAL;
@@ -1105,7 +1102,7 @@ oslFileError openFilePath(const OString& filePath, oslFileHandle* pHandle,
}
/* allocate memory for impl structure */
- FileHandle_Impl *pImpl = new FileHandle_Impl(fd, FileHandle_Impl::KIND_FD, filePath);
+ FileHandle_Impl *pImpl = new FileHandle_Impl(fd, FileHandle_Impl::KIND_FD);
if (flags & O_RDWR)
pImpl->m_state |= State::Writeable;
diff --git a/sal/osl/unx/file_impl.hxx b/sal/osl/unx/file_impl.hxx
index 9ab44ef55fd2..078474cf05ff 100644
--- a/sal/osl/unx/file_impl.hxx
+++ b/sal/osl/unx/file_impl.hxx
@@ -49,7 +49,7 @@ oslFileError openFile(
mode_t mode);
oslFileError openFilePath(
- const OString& filePath,
+ const char* cpFilePath,
oslFileHandle* pHandle,
sal_uInt32 uFlags, mode_t mode );