Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8c935e36
authored
Dec 03, 2020
by
Oliver Woodman
Committed by
Ian Baker
Jan 11, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Merge pull request #8154 from samoylenkodmitry:handle_out_of_space
PiperOrigin-RevId: 345428731
parent
2516e94e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java
View file @
8c935e36
...
...
@@ -409,18 +409,20 @@ public final class SimpleCache implements Cache {
Assertions
.
checkNotNull
(
cachedContent
);
Assertions
.
checkState
(
cachedContent
.
isFullyLocked
(
position
,
length
));
if
(!
cacheDir
.
exists
())
{
// For some reason the cache directory doesn't exist. Make a best effort to create it.
cacheDir
.
mkdirs
();
// The cache directory has been deleted from underneath us. Recreate it, and remove in-memory
// spans corresponding to cache files that no longer exist.
createCacheDirectories
(
cacheDir
);
removeStaleSpans
();
}
evictor
.
onStartFile
(
this
,
key
,
position
,
length
);
// Randomly distribute files into subdirectories with a uniform distribution.
File
file
Dir
=
new
File
(
cacheDir
,
Integer
.
toString
(
random
.
nextInt
(
SUBDIRECTORY_COUNT
)));
if
(!
file
Dir
.
exists
())
{
fileDir
.
mkdir
(
);
File
cacheSub
Dir
=
new
File
(
cacheDir
,
Integer
.
toString
(
random
.
nextInt
(
SUBDIRECTORY_COUNT
)));
if
(!
cacheSub
Dir
.
exists
())
{
createCacheDirectories
(
cacheSubDir
);
}
long
lastTouchTimestamp
=
System
.
currentTimeMillis
();
return
SimpleCacheSpan
.
getCacheFile
(
fileDir
,
cachedContent
.
id
,
position
,
lastTouchTimestamp
);
return
SimpleCacheSpan
.
getCacheFile
(
cacheSubDir
,
cachedContent
.
id
,
position
,
lastTouchTimestamp
);
}
@Override
...
...
@@ -548,10 +550,10 @@ public final class SimpleCache implements Cache {
/** Ensures that the cache's in-memory representation has been initialized. */
private
void
initialize
()
{
if
(!
cacheDir
.
exists
())
{
if
(!
cacheDir
.
mkdirs
())
{
String
message
=
"Failed to create cache directory: "
+
cacheDir
;
Log
.
e
(
TAG
,
message
);
initializationException
=
new
CacheException
(
message
)
;
try
{
createCacheDirectories
(
cacheDir
)
;
}
catch
(
CacheException
e
)
{
initializationException
=
e
;
return
;
}
}
...
...
@@ -834,6 +836,14 @@ public final class SimpleCache implements Cache {
return
Long
.
parseLong
(
fileName
.
substring
(
0
,
fileName
.
indexOf
(
'.'
)),
/* radix= */
16
);
}
private
static
void
createCacheDirectories
(
File
cacheDir
)
throws
CacheException
{
if
(!
cacheDir
.
mkdirs
())
{
String
message
=
"Failed to create cache directory: "
+
cacheDir
;
Log
.
e
(
TAG
,
message
);
throw
new
CacheException
(
message
);
}
}
private
static
synchronized
boolean
lockFolder
(
File
cacheDir
)
{
return
lockedCacheDirs
.
add
(
cacheDir
.
getAbsoluteFile
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment