Skip to content

Commit

Permalink
refactor & cleanup parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
robinrodricks committed Jul 16, 2019
1 parent e5f347c commit 309eec3
Show file tree
Hide file tree
Showing 15 changed files with 3,018 additions and 2,838 deletions.
6 changes: 3 additions & 3 deletions FluentFTP/Client/FtpClient_Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public virtual void Connect() {
#endif

// Create the parser even if the auto-OS detection failed
m_listParser.Init(m_systemType);
m_listParser.Init(m_serverOS);

// FIX : #318 always set the type when we create a new connection
ForceSetDataType = true;
Expand Down Expand Up @@ -486,8 +486,8 @@ public virtual void Connect() {
}
#endif

// Create the parser even if the auto-OS detection failed
m_listParser.Init(m_systemType);
// Create the parser after OS auto-detection
m_listParser.Init(m_serverOS);
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions FluentFTP/Client/FtpClient_Listing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public FtpListItem[] GetListing(string path, FtpListOption options) {

try {
item = m_listParser.ParseSingleLine(path, buf, m_capabilities, machineList);
} catch (FtpListParser.CriticalListParseException) {
} catch (FtpListParseException) {
this.LogStatus(FtpTraceLevel.Verbose, "Restarting parsing from first entry in list");
i = -1;
lst.Clear();
Expand Down Expand Up @@ -689,7 +689,7 @@ public FtpListItem[] EndGetListing(IAsyncResult ar) {
{
item = m_listParser.ParseSingleLine(path, buf, m_capabilities, machineList);
}
catch (FtpListParser.CriticalListParseException)
catch (FtpListParseException)
{
this.LogStatus(FtpTraceLevel.Verbose, "Restarting parsing from first entry in list");
i = -1;
Expand Down
16 changes: 8 additions & 8 deletions FluentFTP/Client/FtpClient_Management.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2033,8 +2033,8 @@ public virtual DateTime GetModifiedTime(string path, FtpDate type = FtpDate.Orig
date = reply.Message.GetFtpDate(DateTimeStyles.AssumeUniversal);

// convert server timezone to UTC, based on the TimeOffset property
if (type != FtpDate.Original && m_listParser.hasTimeOffset) {
date = (date - m_listParser.timeOffset);
if (type != FtpDate.Original && m_listParser.HasTimeOffset) {
date = (date - m_listParser.TimeOffset);
}

// convert to local time if wanted
Expand Down Expand Up @@ -2110,9 +2110,9 @@ public DateTime EndGetModifiedTime(IAsyncResult ar) {
date = reply.Message.GetFtpDate(DateTimeStyles.AssumeUniversal);

// convert server timezone to UTC, based on the TimeOffset property
if (type != FtpDate.Original && m_listParser.hasTimeOffset)
if (type != FtpDate.Original && m_listParser.HasTimeOffset)
{
date = (date - m_listParser.timeOffset);
date = (date - m_listParser.TimeOffset);
}

// convert to local time if wanted
Expand Down Expand Up @@ -2161,8 +2161,8 @@ public virtual void SetModifiedTime(string path, DateTime date, FtpDate type = F
#endif

// convert UTC to server timezone, based on the TimeOffset property
if (type != FtpDate.Original && m_listParser.hasTimeOffset) {
date = (date + m_listParser.timeOffset);
if (type != FtpDate.Original && m_listParser.HasTimeOffset) {
date = (date + m_listParser.TimeOffset);
}

// set modified date of a file
Expand Down Expand Up @@ -2237,9 +2237,9 @@ public void EndSetModifiedTime(IAsyncResult ar) {
#endif

// convert UTC to server timezone, based on the TimeOffset property
if (type != FtpDate.Original && m_listParser.hasTimeOffset)
if (type != FtpDate.Original && m_listParser.HasTimeOffset)
{
date = (date + m_listParser.timeOffset);
date = (date + m_listParser.TimeOffset);
}

// set modified date of a file
Expand Down
11 changes: 4 additions & 7 deletions FluentFTP/Client/FtpClient_Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ public FtpParser ListingParser {
m_parser = value;

// configure parser
m_listParser.parser = value;
m_listParser.parserConfirmed = false;
m_listParser.CurrentParser = value;
m_listParser.ParserConfirmed = false;
}
}

Expand All @@ -636,9 +636,6 @@ public CultureInfo ListingCulture {
get { return m_parserCulture; }
set {
m_parserCulture = value;

// configure parser
m_listParser.parserCulture = value;
}
}

Expand All @@ -655,8 +652,8 @@ public double TimeOffset {
// configure parser
int hours = (int)Math.Floor(m_timeDiff);
int mins = (int)Math.Floor((m_timeDiff - Math.Floor(m_timeDiff)) * 60);
m_listParser.timeOffset = new TimeSpan(hours, mins, 0);
m_listParser.hasTimeOffset = m_timeDiff != 0;
m_listParser.TimeOffset = new TimeSpan(hours, mins, 0);
m_listParser.HasTimeOffset = m_timeDiff != 0;
}
}

Expand Down
17 changes: 17 additions & 0 deletions FluentFTP/Exceptions/FtpListParseException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace FluentFTP.Exceptions {
/// <summary>
/// This exception is thrown by FtpListParser.
/// </summary>
public class FtpListParseException : Exception {
/// <summary>
/// Creates a new FtpListParseException.
/// </summary>
public FtpListParseException()
: base("Cannot parse file listing!") {
}
}
}
4 changes: 2 additions & 2 deletions FluentFTP/Helpers/FtpListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public FtpListItem() {
///
/// NOTE TO USER : You should not need to construct this class manually except in advanced cases. Typically constructed by GetListing().
/// </summary>
public FtpListItem(string raw, string name, long size, bool isDir, ref DateTime lastModifiedTime) {
m_input = raw;
public FtpListItem(string record, string name, long size, bool isDir, ref DateTime lastModifiedTime) {
m_input = record;
m_name = name;
m_size = size;
m_type = isDir ? FtpFileSystemObjectType.Directory : FtpFileSystemObjectType.File;
Expand Down
Loading

0 comments on commit 309eec3

Please sign in to comment.