fix touch() error on android

This commit is contained in:
James Zhan 2017-08-31 16:30:46 +10:00
parent 2ccf12970c
commit 487e519251
1 changed files with 6 additions and 1 deletions

View File

@ -13,6 +13,7 @@ var NativeAppEventEmitter = require('react-native').NativeAppEventEmitter; // i
var DeviceEventEmitter = require('react-native').DeviceEventEmitter; // Android var DeviceEventEmitter = require('react-native').DeviceEventEmitter; // Android
var base64 = require('base-64'); var base64 = require('base-64');
var utf8 = require('utf8'); var utf8 = require('utf8');
var isIOS = require('react-native').Platform.OS === 'ios';
var RNFSFileTypeRegular = RNFSManager.RNFSFileTypeRegular; var RNFSFileTypeRegular = RNFSManager.RNFSFileTypeRegular;
var RNFSFileTypeDirectory = RNFSManager.RNFSFileTypeDirectory; var RNFSFileTypeDirectory = RNFSManager.RNFSFileTypeDirectory;
@ -503,10 +504,14 @@ var RNFS = {
touch(filepath: string, mtime?: Date, ctime?: Date): Promise<void> { touch(filepath: string, mtime?: Date, ctime?: Date): Promise<void> {
if (ctime && !(ctime instanceof Date)) throw new Error('touch: Invalid value for argument `ctime`'); if (ctime && !(ctime instanceof Date)) throw new Error('touch: Invalid value for argument `ctime`');
if (mtime && !(mtime instanceof Date)) throw new Error('touch: Invalid value for argument `mtime`'); if (mtime && !(mtime instanceof Date)) throw new Error('touch: Invalid value for argument `mtime`');
var ctimeTime = 0;
if (isIOS) {
ctimeTime = ctime && ctime.getTime();
}
return RNFSManager.touch( return RNFSManager.touch(
normalizeFilePath(filepath), normalizeFilePath(filepath),
mtime && mtime.getTime(), mtime && mtime.getTime(),
ctime && ctime.getTime() ctimeTime
); );
}, },