Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ExternalCachesDirectoryPath #490

Merged
merged 1 commit into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FS.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ var RNFS = {

MainBundlePath: RNFSManager.RNFSMainBundlePath,
CachesDirectoryPath: RNFSManager.RNFSCachesDirectoryPath,
ExternalCachesDirectoryPath: RNFSManager.RNFSExternalCachesDirectoryPath,
DocumentDirectoryPath: RNFSManager.RNFSDocumentDirectoryPath,
ExternalDirectoryPath: RNFSManager.RNFSExternalDirectoryPath,
ExternalStorageDirectoryPath: RNFSManager.RNFSExternalStorageDirectoryPath,
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath
var RNFS = require('react-native-fs');

// create a path you want to write to
// :warning: on iOS, you cannot write into `RNFS.MainBundlePath`,
// :warning: on iOS, you cannot write into `RNFS.MainBundlePath`,
// but `RNFS.DocumentDirectoryPath` exists on both platforms and is writable
var path = RNFS.DocumentDirectoryPath + '/test.txt';

Expand Down Expand Up @@ -327,6 +327,7 @@ The following constants are available on the `RNFS` export:

- `MainBundlePath` (`String`) The absolute path to the main bundle directory (not available on Android)
- `CachesDirectoryPath` (`String`) The absolute path to the caches directory
- `ExternalCachesDirectoryPath` (`String`) The absolute path to the external caches directory (android only)
- `DocumentDirectoryPath` (`String`) The absolute path to the document directory
- `TemporaryDirectoryPath` (`String`) The absolute path to the temporary directory (falls back to Caching-Directory on Android)
- `LibraryDirectoryPath` (`String`) The absolute path to the NSLibraryDirectory (iOS only)
Expand Down Expand Up @@ -656,7 +657,7 @@ type FSInfoResult = {

### (Android only) `getAllExternalFilesDirs(): Promise<string[]>`

Returns an array with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.
Returns an array with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.

### (iOS only) `pathForGroup(groupIdentifier: string): Promise<string>`

Expand Down
8 changes: 8 additions & 0 deletions android/src/main/java/com/rnfs/RNFSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class RNFSManager extends ReactContextBaseJavaModule {
private static final String RNFSPicturesDirectoryPath = "RNFSPicturesDirectoryPath";
private static final String RNFSTemporaryDirectoryPath = "RNFSTemporaryDirectoryPath";
private static final String RNFSCachesDirectoryPath = "RNFSCachesDirectoryPath";
private static final String RNFSExternalCachesDirectoryPath = "RNFSExternalCachesDirectoryPath";
private static final String RNFSDocumentDirectory = "RNFSDocumentDirectory";

private static final String RNFSFileTypeRegular = "RNFSFileTypeRegular";
Expand Down Expand Up @@ -764,6 +765,13 @@ public Map<String, Object> getConstants() {
constants.put(RNFSExternalDirectoryPath, null);
}

File externalCachesDirectory = this.getReactApplicationContext().getExternalCacheDir();
if (externalCachesDirectory != null) {
constants.put(RNFSExternalCachesDirectoryPath, externalCachesDirectory.getAbsolutePath());
} else {
constants.put(RNFSExternalCachesDirectoryPath, null);
}

return constants;
}
}