This video is a brief troubleshooting session focused on identifying and resolving minor bugs introduced in previous installments of the 'Syncing projects with Google Drive' series. The goal is to stabilize the codebase before proceeding with further feature development.
Key Takeaways
Focuses on immediate bug fixing to ensure a clean development baseline.
Emphasizes the importance of cleaning up technical debt/errors before scaling a project.
Description
Book a call: https://calendly.com/itshassanaziz/discuss-a-project
==== ==== ====
We introduced a couple teeny-tiny bugs in our code from the last couple of videos. Let's take a couple mins and fix them all right now, before we develop any further.
If you're learning something useful from these videos, make sure to subscribe to the channel. I've got a lot of amazing content planned for the future. :)
==== ==== ====
Github: https://github.com/hassanaziz0012/drive-syncer-video
Full Playlist: https://youtube.com/playlist?list=PLTGiYd8gFivjVHK2xB7TLf7XLW8rmKXRM&si=L97UpFIHgfHbvLMT
LINKS
Website: https://www.hassandev.me
Portfolio: https://www.hassandev.me/work
YouTube: https://www.youtube.com/@itshassanaziz?sub_confirmation=1
My Book: https://www.hassandev.me/designing-websites
X / Twitter: https://x.com/nothassanaziz
Transcript
Auto-generated transcript
Good morning everyone, how is everyone doing? We're back in the DriveSyncer project as always and we're going to build a couple new features. So yeah, let me just zoom in so you guys can see sometimes I just forget to do that. Now in the previous video, we finished building the new tracker, the sync tracker and the algorithm over here, right? And the last step was to delete the files from Google Drive right so that's what we did in the previous video in this video I just want to fix a few bugs and make a small tweaks here and there and in the upcoming videos we're going to be implementing something even more amazing but no spoilers for now let's start fixing some bugs so one of the things I noticed when I was going through the project code later after a video was right here in the project exists function over here you'll see that this function project exists is supposed to return a boolean right whether the project exists or not but if you look closely at the query over here it doesn't actually check for the folder name does it it just checks whether the folder is in the parents which is the I guess the programming folder and it's not trashed and it's my type is folder so basically we're looking for literally any folder at all in the programming base folder we're not even checking whether the folder name matches and all the other things match right so yeah this is obviously the wrong the wrong query over here and so we need to fix that and luckily for us this is a simple fix all we need to do is say name and a string over here and then and mime type and the rest of the query now this name is going to be t.folder.name right here and with that we fixed the first bug of this project. Now the second thing I want to do is I want to clean up the logs a bit. So over here in the walk project tree function this is going to output the entire project tree every single time it walks it right but this is really not useful anymore. The only reason we added these logs in the first place was when we were actually building this function and we wanted to make sure that we were getting the correct output that the function was doing the right stuff right but since we've confirmed that these logs are no longer necessary and they're just polluting the entire you know the entire terminal right so we're just going to comment out all of these print statements and that's going to be a much cleaner much more easier to read log file right now that's really all i wanted to do for now so let's do a quick test and see whether the google drive sync process is actually working let's just make sure that our program is working and we didn't break anything before I do that let me empty out my base folder over here you can see I uploaded a couple projects but I gonna move that to trash and start fresh over here now let run this and see what happens by the way we can also before we actually run this we can also go into the config file over here where is it there we go and see which project we actually uploading so you can see I'm uploading the drive sinker video project from my programming folder okay so now that we've confirmed that let's go ahead and run this and see what happens it's going to upload this whole folder right and as you can see it's uploading all of the folders and files in this project. It's skipping the stuff I don't want to upload like the sensitive files like client and token.json, the git folder and so on and so forth. Everything's working perfectly fine. Cool. Awesome. Now let's try uploading the entire thing again. Just see what happens. Okay, the project already exists. It's walking the project tree. That makes sense. And it just skipped everything perfectly fine. Awesome. Alright, So this time I've re-enabled the progress bars and redirected all of our logs to the log file You can do the same thing by uncommenting this line over here render bars in the sync.go.cmd file And in the main.go file, you can uncomment these lines to configure the logger This will send all of the logs to the log file And we'll be able to see progress bars as soon as we uncomment this renders bar function Okay, and then let's see what happens if I run this again This should render a progress bar and we should see some upload progress over here and you can see it tries to upload but it just stops midway and this is because it Finds that the entire project has already been uploaded And so it just stops right there and it doesn't upload any further files after that now This does work for now, but I can already see A potential issue occurring down the line And that is what happens when we have zero total files to upload and this can happen when we're basically just skipping all the files because they've already been uploaded now this doesn't happen right now but i can tell you in the near future we're going to be implementing spoiler alert we're going to be implementing our own git ignore parser basically our own implementation that will parse git ignore files and all the complex patterns that you can have in a git ignore file and once we implement that over here up here in the count total files function this is going to return zero new files if you've already uploaded the entire project and there are no new files to be uploaded right and if that is the case this function will return zero files and so what happens if this progress bar is trying to render and there are zero total files to upload and i can tell you what's going to happen if you if you go over to the progress bar function over here you can see that we're trying to divide by the total number of files right if the total number of files is zero what happens when you try to divide a number by zero, you get undefined because division by zero is undefined. See this, no matter what number I try to divide by zero, it's just going to be undefined because you cannot divide by zero It just mathematically impossible So in this render progress bar function we need to add a special case where if the total files is zero then we need to handle that separately from all of this stuff over here right again this is not a not an issue right now as you can see we do see 18 files to be uploaded over here right now but in the future when we create our own custom git ignore parser this is going to be an issue so let's just fix that ahead of time okay so first of all i just want to take this entire string over here where we construct the actual bar string and create a new function down here. I'll call this build bar and it's going to return a string. There we go. Return and then just paste that sprint f call over here. Up here we can just call this function and there we go. Now it's going to need some arguments over here so let's fill them in. The progress is just going to be a pointer to models.upload progress. The filled and the empty are going to be integers and the percent is going to be a float 64 there we go now all we need to do is pass these in so pass in the progress the filled the empty and the percent there we go and this will make sure that we're building the bar properly now the special case is going to be up here where we say if progress dot solo files equal zero then we're going to say return build bar we'll pass in the progress for the filled we'll just say zero because there are zero files to be uploaded and so zero files will be uploaded for the empty as well we'll say zero and then the percent we'll say 100 because since there are zero files to be uploaded the upload has just finished by default and then we can just say 100 progress has been reached right just by default because there are no files to be uploaded and that's that's pretty much all we need to do for this video again quick recap uh we fixed where is it We fixed the project exists function over here in tracker.go by making sure that we're checking the folder name as well We also commented out all of the print statements in the walk project tree function just because they were polluting the entire terminal output and we don't really need them anymore and finally in the render progress bar function we Refactored it a bit to also be able to handle the case when total files equals zero and again just as a reminder the only reason we need to handle this is because we're going to be building our own gitignore parser in the very near future probably starting in the next video or the video after that and the reason we need that is because if you look at the gitignore file right here it currently only supports file names right our current gitignore parser only supports direct file names if I try to add a complex pattern over here like say I don't know something like this ignore all PyCache folders. If you used Python before this will be familiar to you. Basically what this pattern is saying is that we want to ignore all of the PyCache folders and all of the files inside them But the current gitignore parser that we have in this application will not be able to parse this going to treat it like a file name like a literal file name and that just not going to work right so i want to be able to handle complex patterns like these patterns like let say we have a folder called bar and then we ignore all of the folders inside it and then we have another folder subfolder called foo and so on and so forth right i want to be able to handle complex patterns like this because real world projects have real gitignore files that have complex patterns like these. Right. And so if we want our application to be complete we want to be able to handle all of those all of those different gitignore patterns. And that is why I wanted to build my own custom gitignore parser. And that is why we wanted to be able to handle the total files equals zero case. I actually have a little diagram I drew in Excalidraw over here to actually explain the entire gitignore process. This is just a sneak peek for now guys. I'm going to explain this entire thing in the next video or the video after that when we start actually building this new custom gitignore parser. And the reason I built this is because parsing a gitignore file had so many different rules and patterns that I needed to make sure that I'm handling and it was just such a complex process that I just couldn't wrap my head around it and so I thought it would be easier for me to build some sort of draw some sort of a flow chart or something to explain my thought process and then I can just follow that and so this is what I drew up it explains the entire flow the entire algorithm we're going to follow and implement in the future videos and it has all of the rules that I want to make sure I'm handling all the patterns that I want to make sure I'm handling in the ignore files we're going to go through this entire thing in the next video when we start implementing the git ignore parser for now we're done with this video thank you for watching i hope you're following along with the project i hope you're learning new things just as i am and yeah stay tuned for the next episode we're going to be building our own custom git ignore parser if that's not exciting then i don't know what is like comment subscribe and if you're still here watching the video let me just do a quick cta uh this is my personal website um i have my portfolio and stuff over here i promote my youtube channel over here there's some testimonials from other business owners that i've helped and that i've worked with and basically what i do for work is i'm a freelance developer i build websites apps software and stuff like that and so if you have a project like that and you want me to work with you then just get in touch with me over here i do a free intro call you can find the link for that in the description and we can work together and build your project and remember it never hurts to talk the the first call is free you can book a call with me in the description and we can talk about your project and we can build it together so if that's something you're interested in if you want me to work on your project alongside you then book a call with me and let's get it done other than that thank you for watching the video and i'll see you in the next one
Share this article
Link copied!
Share it on Instagram.
All great things started with a conversation
If you've got a cool project or opportunity and you want me to be a part of it, set up a free meeting with me here, and let's talk. 😊