@@ -1993,22 +1993,24 @@ class EncryptedFS {
1993
1993
// It must continue the loop, by restarting the loop with an inherited transaction context
1994
1994
// This ensures that handling the existing inode is consistent
1995
1995
let raced = false ;
1996
- let _tran : DBTransaction | undefined = tran ;
1997
- let _tranRelease : ResourceRelease | undefined = undefined ;
1996
+ let tran_ : DBTransaction | null = null ;
1997
+ let tranRelease_ : ResourceRelease | null = null ;
1998
1998
// Loop necessary due to following symlinks and optional `O_CREAT` file creation
1999
1999
while ( true ) {
2000
2000
if ( navigated . target != null ) {
2001
2001
// Handle existing target
2002
- if ( _tran == null && _tranRelease == null ) {
2002
+ if ( tran != null ) {
2003
+ tran_ = tran ;
2004
+ } else if ( tran_ == null || tranRelease_ == null ) {
2003
2005
const tranAcquire = this . iNodeMgr . transaction ( navigated . target ) ;
2004
- [ _tranRelease , _tran ] = ( await tranAcquire ( ) ) as [
2006
+ [ tranRelease_ , tran_ ] = ( await tranAcquire ( ) ) as [
2005
2007
ResourceRelease ,
2006
2008
DBTransaction ,
2007
2009
] ;
2008
2010
}
2009
2011
let e : Error | undefined ;
2010
2012
try {
2011
- const target = await this . iNodeMgr . get ( navigated . target , _tran ) ;
2013
+ const target = await this . iNodeMgr . get ( navigated . target , tran_ ) ;
2012
2014
if ( target == null ) {
2013
2015
// Try to find the target again
2014
2016
navigated = await this . navigate ( path , false ) ;
@@ -2034,7 +2036,7 @@ class EncryptedFS {
2034
2036
path ,
2035
2037
// Only preserve the transaction context if it was inherited
2036
2038
// from a coalesced call, as it would already have be for `navigated.dir`
2037
- raced ? _tran : undefined ,
2039
+ raced ? tran_ : undefined ,
2038
2040
) ;
2039
2041
// Restart the opening procedure with the new target
2040
2042
continue ;
@@ -2074,27 +2076,27 @@ class EncryptedFS {
2074
2076
flags & constants . O_TRUNC &&
2075
2077
flags & ( constants . O_WRONLY | constants . O_RDWR )
2076
2078
) {
2077
- await this . iNodeMgr . fileClearData ( navigated . target , _tran ) ;
2079
+ await this . iNodeMgr . fileClearData ( navigated . target , tran_ ) ;
2078
2080
await this . iNodeMgr . fileSetBlocks (
2079
2081
navigated . target ,
2080
2082
Buffer . alloc ( 0 ) ,
2081
2083
this . blockSize ,
2082
2084
undefined ,
2083
- _tran ,
2085
+ tran_ ,
2084
2086
) ;
2085
2087
}
2086
2088
// Terminates loop, creates file descriptor
2087
- return await createFd ( flags , navigated . target , _tran ! ) ;
2089
+ return await createFd ( flags , navigated . target , tran_ ! ) ;
2088
2090
}
2089
2091
} catch ( e_ ) {
2090
2092
e = e_ ;
2091
2093
throw e_ ;
2092
2094
} finally {
2093
- if ( _tranRelease != null ) {
2094
- await _tranRelease ( e ) ;
2095
+ if ( tranRelease_ != null ) {
2096
+ await tranRelease_ ( e ) ;
2095
2097
// Clear the transaction variables
2096
- _tran = undefined ;
2097
- _tranRelease = undefined ;
2098
+ tran_ = null ;
2099
+ tranRelease_ = null ;
2098
2100
}
2099
2101
}
2100
2102
} else {
@@ -2112,17 +2114,19 @@ class EncryptedFS {
2112
2114
ResourceRelease ,
2113
2115
INodeIndex ,
2114
2116
] ;
2115
- if ( _tran == null && _tranRelease == null ) {
2117
+ if ( tran != null ) {
2118
+ tran_ = tran ;
2119
+ } else if ( tran_ == null || tranRelease_ == null ) {
2116
2120
const tranAcquire = this . iNodeMgr . transaction ( ino , navigated . dir ) ;
2117
- [ _tranRelease , _tran ] = ( await tranAcquire ( ) ) as [
2121
+ [ tranRelease_ , tran_ ] = ( await tranAcquire ( ) ) as [
2118
2122
ResourceRelease ,
2119
2123
DBTransaction ,
2120
2124
] ;
2121
2125
}
2122
2126
// INode may be created while waiting for lock
2123
2127
// Transaction is maintained and not released
2124
2128
// This is to ensure that the already created locks are held
2125
- if ( ( await this . iNodeMgr . get ( ino , _tran ) ) != null ) {
2129
+ if ( ( await this . iNodeMgr . get ( ino , tran_ ) ) != null ) {
2126
2130
navigated . target = ino ;
2127
2131
await inoRelease ( ) ;
2128
2132
raced = true ;
@@ -2132,7 +2136,7 @@ class EncryptedFS {
2132
2136
try {
2133
2137
const navigatedDirStat = await this . iNodeMgr . statGet (
2134
2138
navigated . dir ,
2135
- _tran ,
2139
+ tran_ ,
2136
2140
) ;
2137
2141
// Cannot create if the current directory has been unlinked from its parent directory
2138
2142
if ( navigatedDirStat . nlink < 2 ) {
@@ -2158,26 +2162,26 @@ class EncryptedFS {
2158
2162
} ,
2159
2163
this . blockSize ,
2160
2164
undefined ,
2161
- _tran ,
2165
+ tran_ ,
2162
2166
) ;
2163
2167
await this . iNodeMgr . dirSetEntry (
2164
2168
navigated . dir ,
2165
2169
navigated . name ,
2166
2170
ino ! ,
2167
- _tran ,
2171
+ tran_ ,
2168
2172
) ;
2169
2173
// Terminates loop, creates file descriptor
2170
- return await createFd ( flags , ino ! , _tran ! ) ;
2174
+ return await createFd ( flags , ino ! , tran_ ! ) ;
2171
2175
} catch ( e_ ) {
2172
2176
e = e_ ;
2173
2177
throw e_ ;
2174
2178
} finally {
2175
2179
await inoRelease ( e ) ;
2176
- if ( _tranRelease != null ) {
2177
- await _tranRelease ( e ) ;
2180
+ if ( tranRelease_ != null ) {
2181
+ await tranRelease_ ( e ) ;
2178
2182
// Clear the transaction variables
2179
- _tran = undefined ;
2180
- _tranRelease = undefined ;
2183
+ tran_ = null ;
2184
+ tranRelease_ = null ;
2181
2185
}
2182
2186
}
2183
2187
}
0 commit comments