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

HPCC-11841 Add utility method getSortedDirectoryIterator() #10602

Merged
merged 1 commit into from
Nov 18, 2017

Conversation

wangkx
Copy link
Member

@wangkx wangkx commented Nov 3, 2017

Signed-off-by: wangkx kevin.wang@lexisnexis.com

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Testing:

@hpcc-jirabot
Copy link

@wangkx
Copy link
Member Author

wangkx commented Nov 3, 2017

@jakesmith please review.

@@ -227,6 +227,13 @@ class GitRepositoryFile : implements IFile, public CInterface
return createGitRepositoryDirectoryIterator(dirName, mask, sub, includeDirs);
}
}
IDirectoryIterator *directoryFilesSorted(SortDirectoryMode mode, bool rev, const char *mask=NULL, bool sub=false, bool includedirs=false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing 'virtual'
and don't need default param. definitions (which are in virtual decl. in header)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use 'override' consistently too really. They prevent mishaps, like getting the override prototype wrong.

if (SD_nosort == mode)
return baseIter;
return new CSortedDirectoryIterator(*baseIter, mode, rev, includedirs);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am wondering since this is a universal implementation, if it wouldn't be better to implement this in a an abstract CFileBase class.
i.e. the git, archive, sockfile impls. can inherit from that rather than re-implement it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will implement this in new CFileBase. Since the new directoryFilesSorted() will be removed from the git, archive, etc., I think it would be clear if I rebase the changes into 1 commit for you to review.

@@ -385,6 +385,13 @@ class ArchiveFile : implements IFile, public CInterface
return createArchiveDirectoryIterator(dirName, mask, sub, includeDirs);
}
}
IDirectoryIterator *directoryFilesSorted(SortDirectoryMode mode, bool rev, const char *mask=NULL, bool sub=false, bool includedirs=false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, should be consistent with 'virtual' and don't need default params.
And would benefit from 'override', but should add to other methods to be consistent.

@@ -632,4 +633,67 @@ const static bool filenamesAreCaseSensitive = false;
const static bool filenamesAreCaseSensitive = true;
#endif

class jlib_decl CSortedDirectoryIterator : implements IDirectoryIterator, public CInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use CSimpleInterface unless you need beforeDispose
And better to use templaces to avoid double inheritance.
so:
public CSimpleInterfaceOf

sortedFileCount = sortedFiles.length();
}

IMPLEMENT_IINTERFACE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary with above change.


IMPLEMENT_IINTERFACE

virtual bool first()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to use 'override' here and other overloads.


virtual __int64 getFileSize()
{
return curDirectoryEntry ? curDirectoryEntry->size : 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think should return -1 if invalid (see other implementations)

@jakesmith
Copy link
Member

@wangkx - a few comments.

@wangkx
Copy link
Member Author

wangkx commented Nov 10, 2017

@jakesmith please review.

@wangkx wangkx changed the title HPCC-11841 Add directoryFilesSorted() HPCC-11841 Add directoryFilesSorted() to IFile Nov 10, 2017
@wangkx wangkx changed the title HPCC-11841 Add directoryFilesSorted() to IFile HPCC-11841 Add utility method getSortedDirectoryIterator() Nov 13, 2017
@wangkx
Copy link
Member Author

wangkx commented Nov 13, 2017

@jakesmith the CFileBase is removed and the getSortedDirectoryIterator() is added. Please review.

sortedFileIndex++;
return true;
}
virtual bool isValid() override { return cur != NULL; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: nullptr preferable

@@ -632,4 +632,70 @@ const static bool filenamesAreCaseSensitive = false;
const static bool filenamesAreCaseSensitive = true;
#endif

class jlib_decl CSortedDirectoryIterator : public CSimpleInterfaceOf<IDirectoryIterator>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class should be move to .cpp

};

extern jlib_decl IDirectoryIterator *getSortedDirectoryIterator(IFile *directory, SortDirectoryMode mode, bool rev, const char *mask, bool sub, bool includedirs);
extern jlib_decl IDirectoryIterator *getSortedDirectoryIterator(const char *dirName, SortDirectoryMode mode, bool rev, const char *mask, bool sub, bool includedirs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should default params in same way as directoryFiles

@jakesmith
Copy link
Member

@wangkx - a couple of comments.

@wangkx
Copy link
Member Author

wangkx commented Nov 13, 2017

@jakesmith please review my changes.

@@ -632,4 +632,7 @@ const static bool filenamesAreCaseSensitive = false;
const static bool filenamesAreCaseSensitive = true;
#endif

extern jlib_decl IDirectoryIterator *getSortedDirectoryIterator(IFile *directory, SortDirectoryMode mode, bool rev, const char *mask = NULL, bool sub = false, bool includedirs = false);
extern jlib_decl IDirectoryIterator *getSortedDirectoryIterator(const char *dirName, SortDirectoryMode mode, bool rev, const char *mask = NULL, bool sub = false, bool includedirs = false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr preferable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would make sense to default mode and rev here too, since others have defaults and common usage is going to be mode=SD_byname and rev=false

@@ -6755,3 +6755,87 @@ timestamp_type getTimeStamp(IFile * file)
file->getTime(nullptr, &modified, nullptr);
return modified.getTimeStamp();
}

class jlib_decl CSortedDirectoryIterator : public CSimpleInterfaceOf<IDirectoryIterator>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double space after public

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need/want jlib_decl here.

@jakesmith
Copy link
Member

@wangkx - some minor comments.

@wangkx
Copy link
Member Author

wangkx commented Nov 17, 2017

@jakesmith please review my last commit.

@jakesmith
Copy link
Member

@wangkx - looks good.

@richardkchapman - ready to merge.

@wangkx
Copy link
Member Author

wangkx commented Nov 17, 2017

I am going to squash the commits before merging.

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
@HPCCSmoketest
Copy link
Contributor

Automated Smoketest: ✅
Sha: a0f2816
Empty table
Build: success
Build: success
ECL Watch: Rebuilding Site
Empty table
Install hpccsystems-platform-community_6.5.0-trunk0.el7.x86_64.rpm
HPCC Start: OK

Unit tests result:

Test total passed failed errors timeout
unittest 117 117 0 0 0
wutoolTest(Dali) 19 19 0 0 0
wutoolTest(Cassandra) 19 19 0 0 0

Regression test result:

phase total pass fail
setup (hthor) 11 11 0
setup (thor) 11 11 0
setup (roxie) 11 11 0
test (hthor) 745 745 0
test (thor) 640 640 0
test (roxie) 773 773 0

HPCC Stop: OK
HPCC Uninstall: OK

@wangkx
Copy link
Member Author

wangkx commented Nov 17, 2017

@richardkchapman this PR is ready to be merged.

@richardkchapman richardkchapman merged commit 6f00498 into hpcc-systems:master Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants