Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
56b504b0
Commit
56b504b0
authored
4 years ago
by
Rye Mutt
Browse files
Options
Downloads
Patches
Plain Diff
More efficient cache directory structure for some filesystems
parent
529e0bd1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indra/llfilesystem/lldiskcache.cpp
+22
-19
22 additions, 19 deletions
indra/llfilesystem/lldiskcache.cpp
indra/llfilesystem/lldiskcache.h
+8
-2
8 additions, 2 deletions
indra/llfilesystem/lldiskcache.h
with
30 additions
and
21 deletions
indra/llfilesystem/lldiskcache.cpp
+
22
−
19
View file @
56b504b0
...
@@ -46,9 +46,19 @@ LLDiskCache::LLDiskCache(const std::string cache_dir,
...
@@ -46,9 +46,19 @@ LLDiskCache::LLDiskCache(const std::string cache_dir,
mMaxSizeBytes
(
max_size_bytes
),
mMaxSizeBytes
(
max_size_bytes
),
mEnableCacheDebugInfo
(
enable_cache_debug_info
)
mEnableCacheDebugInfo
(
enable_cache_debug_info
)
{
{
mCacheFilename
Prefix
=
"sl_cache"
;
mCacheFilename
Ext
=
"
.
sl_cache"
;
LLFile
::
mkdir
(
cache_dir
);
createCache
();
}
void
LLDiskCache
::
createCache
()
{
LLFile
::
mkdir
(
mCacheDir
);
std
::
vector
<
std
::
string
>
uuidprefix
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
};
for
(
auto
&
prefixchar
:
uuidprefix
)
{
LLFile
::
mkdir
(
absl
::
StrCat
(
mCacheDir
,
gDirUtilp
->
getDirDelimiter
(),
prefixchar
));
}
}
}
void
LLDiskCache
::
purge
()
void
LLDiskCache
::
purge
()
...
@@ -70,11 +80,11 @@ void LLDiskCache::purge()
...
@@ -70,11 +80,11 @@ void LLDiskCache::purge()
#endif
#endif
if
(
boost
::
filesystem
::
is_directory
(
cache_path
))
if
(
boost
::
filesystem
::
is_directory
(
cache_path
))
{
{
for
(
auto
&
entry
:
boost
::
make_iterator_range
(
boost
::
filesystem
::
directory_iterator
(
cache_path
),
{}))
for
(
auto
&
entry
:
boost
::
make_iterator_range
(
boost
::
filesystem
::
recursive_
directory_iterator
(
cache_path
),
{}))
{
{
if
(
boost
::
filesystem
::
is_regular_file
(
entry
))
if
(
boost
::
filesystem
::
is_regular_file
(
entry
))
{
{
if
(
entry
.
path
().
string
().
find
(
mCacheFilename
Prefix
)
!=
std
::
string
::
npos
)
if
(
entry
.
path
().
string
().
r
find
(
mCacheFilename
Ext
)
!=
std
::
string
::
npos
)
{
{
uintmax_t
file_size
=
boost
::
filesystem
::
file_size
(
entry
);
uintmax_t
file_size
=
boost
::
filesystem
::
file_size
(
entry
);
const
std
::
string
file_path
=
entry
.
path
().
string
();
const
std
::
string
file_path
=
entry
.
path
().
string
();
...
@@ -182,9 +192,9 @@ const std::string LLDiskCache::assetTypeToString(LLAssetType::EType at)
...
@@ -182,9 +192,9 @@ const std::string LLDiskCache::assetTypeToString(LLAssetType::EType at)
const
std
::
string
LLDiskCache
::
metaDataToFilepath
(
const
LLUUID
&
id
,
const
std
::
string
LLDiskCache
::
metaDataToFilepath
(
const
LLUUID
&
id
,
LLAssetType
::
EType
at
)
LLAssetType
::
EType
at
)
{
{
std
::
string
uuidstr
;
std
::
string
uuidstr
=
id
.
asString
()
;
id
.
toString
(
uuidstr
);
const
auto
&
dirdelim
=
gDirUtilp
->
getDirDelimiter
(
);
return
llformat
(
"%s%s%s_%s"
,
mCacheDir
.
c_str
(),
gDirUtilp
->
getD
ir
D
elim
iter
().
c_
str
()
,
mCacheFilename
Prefix
.
c_str
(),
uuidstr
.
c_str
()
);
return
absl
::
StrCat
(
mCacheDir
,
dirdelim
,
absl
::
string_view
(
&
uuidstr
[
0
],
1
),
d
ir
d
elim
,
uuid
str
,
mCacheFilename
Ext
);
}
}
const
std
::
string
LLDiskCache
::
getCacheInfo
()
const
std
::
string
LLDiskCache
::
getCacheInfo
()
...
@@ -210,16 +220,9 @@ void LLDiskCache::clearCache()
...
@@ -210,16 +220,9 @@ void LLDiskCache::clearCache()
#endif
#endif
if
(
boost
::
filesystem
::
is_directory
(
cache_path
))
if
(
boost
::
filesystem
::
is_directory
(
cache_path
))
{
{
for
(
auto
&
entry
:
boost
::
make_iterator_range
(
boost
::
filesystem
::
directory_iterator
(
cache_path
),
{}))
boost
::
filesystem
::
remove_all
(
cache_path
);
{
if
(
boost
::
filesystem
::
is_regular_file
(
entry
))
createCache
();
{
if
(
entry
.
path
().
string
().
find
(
mCacheFilenamePrefix
)
!=
std
::
string
::
npos
)
{
boost
::
filesystem
::
remove
(
entry
);
}
}
}
}
}
}
}
...
@@ -243,11 +246,11 @@ uintmax_t LLDiskCache::dirFileSize(const std::string dir)
...
@@ -243,11 +246,11 @@ uintmax_t LLDiskCache::dirFileSize(const std::string dir)
#endif
#endif
if
(
boost
::
filesystem
::
is_directory
(
dir_path
))
if
(
boost
::
filesystem
::
is_directory
(
dir_path
))
{
{
for
(
auto
&
entry
:
boost
::
make_iterator_range
(
boost
::
filesystem
::
directory_iterator
(
dir_path
),
{}))
for
(
auto
&
entry
:
boost
::
make_iterator_range
(
boost
::
filesystem
::
recursive_
directory_iterator
(
dir_path
),
{}))
{
{
if
(
boost
::
filesystem
::
is_regular_file
(
entry
))
if
(
boost
::
filesystem
::
is_regular_file
(
entry
))
{
{
if
(
entry
.
path
().
string
().
find
(
mCacheFilename
Prefix
)
!=
std
::
string
::
npos
)
if
(
entry
.
path
().
string
().
r
find
(
mCacheFilename
Ext
)
!=
std
::
string
::
npos
)
{
{
total_file_size
+=
boost
::
filesystem
::
file_size
(
entry
);
total_file_size
+=
boost
::
filesystem
::
file_size
(
entry
);
}
}
...
...
This diff is collapsed.
Click to expand it.
indra/llfilesystem/lldiskcache.h
+
8
−
2
View file @
56b504b0
...
@@ -139,6 +139,12 @@ class LLDiskCache :
...
@@ -139,6 +139,12 @@ class LLDiskCache :
*/
*/
const
std
::
string
assetTypeToString
(
LLAssetType
::
EType
at
);
const
std
::
string
assetTypeToString
(
LLAssetType
::
EType
at
);
/**
* Utility function to create the cache directory structure
*/
void
createCache
();
private:
private:
/**
/**
* The maximum size of the cache in bytes. After purge is called, the
* The maximum size of the cache in bytes. After purge is called, the
...
@@ -156,14 +162,14 @@ class LLDiskCache :
...
@@ -156,14 +162,14 @@ class LLDiskCache :
std
::
string
mCacheDir
;
std
::
string
mCacheDir
;
/**
/**
* The
prefix
inserted at the
start
of a cache file filename to
* The
extension
inserted at the
end
of a cache file filename to
* help identify it as a cache file. It's probably not required
* help identify it as a cache file. It's probably not required
* (just the presence in the cache folder is enough) but I am
* (just the presence in the cache folder is enough) but I am
* paranoid about the cache folder being set to something bad
* paranoid about the cache folder being set to something bad
* like the users' OS system dir by mistake or maliciously and
* like the users' OS system dir by mistake or maliciously and
* this will help to offset any damage if that happens.
* this will help to offset any damage if that happens.
*/
*/
std
::
string
mCacheFilename
Prefix
;
std
::
string
mCacheFilename
Ext
;
/**
/**
* When enabled, displays additional debugging information in
* When enabled, displays additional debugging information in
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment