Skip to content

Commit

Permalink
Stop some callers from bypassing the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
FanDjango committed Dec 28, 2021
1 parent e5b4436 commit edd4d1b
Showing 1 changed file with 45 additions and 44 deletions.
89 changes: 45 additions & 44 deletions FluentFTP/Client/FtpClient_Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,13 +1643,7 @@ protected void SetDataType(FtpDataType type) {
lock (m_lock) {
#endif

// FIX : #291 only change the data type if different
if (CurrentDataType != type || ForceSetDataType) {
// FIX : #318 always set the type when we create a new connection
ForceSetDataType = false;

SetDataTypeNoLock(type);
}
SetDataTypeNoLock(type);

#if !CORE14
}
Expand All @@ -1663,27 +1657,33 @@ protected void SetDataType(FtpDataType type) {
/// <param name="type">ASCII/Binary.</param>
/// <remarks>This method doesn't do any locking to prevent recursive lock scenarios. Callers must do their own locking.</remarks>
private void SetDataTypeNoLock(FtpDataType type) {
FtpReply reply;
switch (type) {
case FtpDataType.ASCII:
if (!(reply = Execute("TYPE A")).Success) {
throw new FtpCommandException(reply);
}
// FIX : #291 only change the data type if different
if (CurrentDataType != type || ForceSetDataType) {
// FIX : #318 always set the type when we create a new connection
ForceSetDataType = false;

break;
FtpReply reply;
switch (type) {
case FtpDataType.ASCII:
if (!(reply = Execute("TYPE A")).Success) {
throw new FtpCommandException(reply);
}

case FtpDataType.Binary:
if (!(reply = Execute("TYPE I")).Success) {
throw new FtpCommandException(reply);
}
break;

break;
case FtpDataType.Binary:
if (!(reply = Execute("TYPE I")).Success) {
throw new FtpCommandException(reply);
}

default:
throw new FtpException("Unsupported data type: " + type.ToString());
}
break;

CurrentDataType = type;
default:
throw new FtpException("Unsupported data type: " + type.ToString());
}

CurrentDataType = type;
}
}

#if ASYNC
Expand All @@ -1693,13 +1693,8 @@ private void SetDataTypeNoLock(FtpDataType type) {
/// <param name="type">ASCII/Binary</param>
/// <param name="token">The token that can be used to cancel the entire process</param>
protected async Task SetDataTypeAsync(FtpDataType type, CancellationToken token = default(CancellationToken)) {
// FIX : #291 only change the data type if different
if (CurrentDataType != type || ForceSetDataType) {
// FIX : #318 always set the type when we create a new connection
ForceSetDataType = false;

await SetDataTypeNoLockAsync(type, token);
}
await SetDataTypeNoLockAsync(type, token);
}

/// <summary>
Expand All @@ -1708,27 +1703,33 @@ private void SetDataTypeNoLock(FtpDataType type) {
/// <param name="type">ASCII/Binary</param>
/// <param name="token">The token that can be used to cancel the entire process</param>
protected async Task SetDataTypeNoLockAsync(FtpDataType type, CancellationToken token = default(CancellationToken)) {
FtpReply reply;
switch (type) {
case FtpDataType.ASCII:
if (!(reply = await ExecuteAsync("TYPE A", token)).Success) {
throw new FtpCommandException(reply);
}
// FIX : #291 only change the data type if different
if (CurrentDataType != type || ForceSetDataType) {
// FIX : #318 always set the type when we create a new connection
ForceSetDataType = false;

break;
FtpReply reply;
switch (type) {
case FtpDataType.ASCII:
if (!(reply = await ExecuteAsync("TYPE A", token)).Success) {
throw new FtpCommandException(reply);
}

case FtpDataType.Binary:
if (!(reply = await ExecuteAsync("TYPE I", token)).Success) {
throw new FtpCommandException(reply);
}
break;

break;
case FtpDataType.Binary:
if (!(reply = await ExecuteAsync("TYPE I", token)).Success) {
throw new FtpCommandException(reply);
}

default:
throw new FtpException("Unsupported data type: " + type.ToString());
}
break;

default:
throw new FtpException("Unsupported data type: " + type.ToString());
}

CurrentDataType = type;
}
}
#endif

Expand Down

0 comments on commit edd4d1b

Please sign in to comment.