-
Notifications
You must be signed in to change notification settings - Fork 10
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
implements passthrough to allow filtering and progress implementation #8
base: master
Are you sure you want to change the base?
Conversation
Thank you for the contribution! I think this is a reasonable enhancement in making copying jobs more observable, but there are several things need to be discussed. As I have mentioned in issue #3, I think a virtual filesystem like I believe that Here is my opinion of filtering. I think a dropin replace for CopyDirFsToRemote(localFS fs.FS, remoteTarget string, *DirTransferOption) error
var (
SkipAll = fs.SkipAll
SkipDir = fs.SkipDir
// this is added for skipping files
SkipFile = errors.New("skip this file")
)
type DirTransferOption struct {
...
// WalkDirFunc is called on visiting each file or directory.
// Compared to fs.WalkDirFunc, It adds additional capability to
// skip certain files when SkipFile error is returned.
WalkDirFunc fs.WalkDirFunc
}
// here is the WalkDirFunc signature for reference
//
// WalkDirFunc is the type of the function called by [WalkDir] to visit
// each file or directory.
//
// The path argument contains the argument to [WalkDir] as a prefix.
// That is, if WalkDir is called with root argument "dir" and finds a file
// named "a" in that directory, the walk function will be called with
// argument "dir/a".
//
// The d argument is the [DirEntry] for the named path.
//
// The error result returned by the function controls how [WalkDir]
// continues. If the function returns the special value [SkipDir], WalkDir
// skips the current directory (path if d.IsDir() is true, otherwise
// path's parent directory). If the function returns the special value
// [SkipAll], WalkDir skips all remaining files and directories. Otherwise,
// if the function returns a non-nil error, WalkDir stops entirely and
// returns that error.
//
// The err argument reports an error related to path, signaling that
// [WalkDir] will not walk into that directory. The function can decide how
// to handle that error; as described earlier, returning the error will
// cause WalkDir to stop walking the entire tree.
//
// [WalkDir] calls the function with a non-nil err argument in two cases.
//
// First, if the initial [Stat] on the root directory fails, WalkDir
// calls the function with path set to root, d set to nil, and err set to
// the error from [fs.Stat].
//
// Second, if a directory's ReadDir method (see [ReadDirFile]) fails, WalkDir calls the
// function with path set to the directory's path, d set to an
// [DirEntry] describing the directory, and err set to the error from
// ReadDir. In this second case, the function is called twice with the
// path of the directory: the first call is before the directory read is
// attempted and has err set to nil, giving the function a chance to
// return [SkipDir] or [SkipAll] and avoid the ReadDir entirely. The second call
// is after a failed ReadDir and reports the error from ReadDir.
// (If ReadDir succeeds, there is no second call.)
//
// The differences between WalkDirFunc compared to [path/filepath.WalkFunc] are:
//
// - The second argument has type [DirEntry] instead of [FileInfo].
// - The function is called before reading a directory, to allow [SkipDir]
// or [SkipAll] to bypass the directory read entirely or skip all remaining
// files and directories respectively.
// - If a directory read fails, the function is called a second time
// for that directory to report the error.
type WalkDirFunc func(path string, d DirEntry, err error) error |
Thank you for your feedback and for considering my contribution! I appreciate your suggestion regarding the use of a virtual filesystem like Additionally, regarding progress reporting, while I understand your concern about the potential overhead of using As a potential solution, I suggest we handle this pull request by focusing on the implementation of the progress bar. Specifically, we could add an For the file filtering and selection enhancements, we could consider addressing them in a separate pull request. This would allow us to thoroughly discuss and implement the best approach for those features without conflating them with the progress reporting changes. Once again, thank you for your guidance. I look forward to your thoughts on these considerations and how we can proceed. |
You are absolutely right on that, for API & experience consistency, filtering should be able to apply on both upload & download.
I agree, filtering design needs more discussion and consideration. I dig a littler deeper into I suggest using the return For example: // should be readonly and monitoring purpose only ?
type TransferMetaReadOnly struct {
IsDir bool
Name string // file or directory name
Path string // directory path without name, could be absolutely or relatively, depending on condition
TotalSize int64 // bytes
TransferredSize int64 // bytes
Perm os.FileMode // is this necessary ?
} Additionally, a single write/read should be enough for transferring tiny file, but this might not be enough for progress reporting, An extra call to the anonymous function with proper metadata should be executed before write/read, in order to have the "start" and "end" event properly generated. |
Regarding the use of The approach of wrapping func (w *Wrap) Write(p []byte) (n int, err error) {
w.callbackfunc(somestuff) // some stuff to communicate progress
return w.originalStreamIn.Write(p)
} This means that for each chunk written (since If we were to wrap I am eager to understand how you envision the solution in more detail. If you could provide further clarification or examples of how you would like the progress reporting to be implemented, I would be more than willing to adapt and implement it accordingly. |
I am really busy on work today. Sorry for the delayed response. No problem, let's go through your design and explain my concern, one by one.
(Feel free to correct me if I didn't get your point) This make sense for the most of time. But, as I have mentioned in previous post: looking a little deeper into implementation of Assuming the first chunk is 4MiB, and the file total size is 16MiB. An error occurs at 2MiB written to Here are some definition issue/corner cases need to be discussed.
That's a lot of discussion above. Let me file a checklist if you are still interested in.
In a nutshell, I hope it can be defined clear and implemented without confusion or undefined behavior. Thank you again for your patience and devotion. |
No worries at all about the delay! I completely understand that work can get busy, and I appreciate you taking the time to provide such a detailed response. It’s clear that we’re both aligned on the complexity and importance of solving this problem in a robust way. I appreciate your thoroughness in outlining the potential issues and the checklist for defining how progress reporting should work. Given the points you’ve raised and the checklist you provided, I’ll take some time to consider and propose a solution that addresses these concerns. I believe this will help us continue iterating on the discussion and refine the approach to ensure we have a clear, well-defined, and reliable implementation. |
I wanted to let you know that I've updated the pull request with a new proposal for the code. In this proposal, I've introduced a new function These methods are responsible for sending the Additionally, the calls to As a small improvement, I've also increased the size of the transfer buffer to try and enhance the transfer speed for small files. I've made an effort to include detailed comments in the code to ensure it is clear and easy to understand. Of course, I’m open to any changes or suggestions you may have. We can take this code as a starting point to align our positions and continue refining the solution. Thank you for your time and feedback! |
Implement callback mechanism for file transfer events and enhance TransferInfo interface with detailed transfer data
Thank you for the detailed explanation! I've noticed a lot of changes since last time. This might need more time for reviewing and advice. |
I've just made a new commit fixing a concurrency issue with the |
Introduces an anonymous function attribute Passthrough in opts param that allows manipulation and filtering objects, which can represent either send or receive jobs.
This could close issue #3