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

Changing cache location and deleting old files #414

Merged
merged 8 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/D2L.Bmx/BmxConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public BmxConfig GetConfiguration() {
}

public void SaveConfiguration( BmxConfig config ) {
if( !Directory.Exists( BmxPaths.BMX_DIR ) ) {
Directory.CreateDirectory( BmxPaths.BMX_DIR );
}
var op = new FileStreamOptions {
Mode = FileMode.OpenOrCreate,
Access = FileAccess.ReadWrite,
Expand Down
7 changes: 4 additions & 3 deletions src/D2L.Bmx/BmxPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ namespace D2L.Bmx;
internal static class BmxPaths {
public static readonly string USER_HOME_DIR = Environment.GetFolderPath( Environment.SpecialFolder.UserProfile );
public static readonly string BMX_DIR = Path.Join( USER_HOME_DIR, ".bmx" );
public static readonly string SESSIONS_FILE_NAME = Path.Join( BMX_DIR, "sessions" );
public static readonly string CACHE_DIR = Path.Join( BMX_DIR, "\\cache" );
public static readonly string SESSIONS_FILE_NAME = Path.Join( CACHE_DIR, "sessions" );
public static readonly string CONFIG_FILE_NAME = Path.Join( BMX_DIR, "config" );
public static readonly string UPDATE_CHECK_FILE_NAME = Path.Join( BMX_DIR, "update_check" );
public static readonly string AWS_CREDS_CACHE_FILE_NAME = Path.Join( BMX_DIR, "awsCredsCache" );
public static readonly string UPDATE_CHECK_FILE_NAME = Path.Join( CACHE_DIR, "updateCheck" );
public static readonly string AWS_CREDS_CACHE_FILE_NAME = Path.Join( CACHE_DIR, "awsCreds" );
}
3 changes: 0 additions & 3 deletions src/D2L.Bmx/Okta/OktaSessionStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ internal interface IOktaSessionStorage {

internal class OktaSessionStorage : IOktaSessionStorage {
void IOktaSessionStorage.SaveSessions( List<OktaSessionCache> sessions ) {
if( !Directory.Exists( BmxPaths.BMX_DIR ) ) {
Directory.CreateDirectory( BmxPaths.BMX_DIR );
}

string jsonString = JsonSerializer.Serialize(
sessions,
Expand Down
7 changes: 7 additions & 0 deletions src/D2L.Bmx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@
next
) => {
await UpdateChecker.CheckForUpdatesAsync( configProvider.GetConfiguration() );
alex-fang0 marked this conversation as resolved.
Show resolved Hide resolved
//Creating new Cache directory and removing old files.
if( !Directory.Exists( BmxPaths.CACHE_DIR ) ) {
Directory.CreateDirectory( BmxPaths.CACHE_DIR );
File.Delete( Path.Join( BmxPaths.BMX_DIR, "awsCredsCache" ) );
File.Delete( Path.Join( BmxPaths.BMX_DIR, "sessions" ) );
File.Delete( Path.Join( BmxPaths.BMX_DIR, "update_check" ) );
}
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to handle exceptions gracefully here for the especially for the cleanup of the old files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think the Directory or File functions error out even if the files don't exist

Copy link
Member

Choose a reason for hiding this comment

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

Mhm, I was more concerned about the other exceptions. Especially for the cleanup part of this (i.e everything aside from CreateDirectory).
https://learn.microsoft.com/en-us/dotnet/api/system.io.file.delete?view=net-7.0#exceptions

Ideally we would like BMX to continue working if for w/e reason it can't actually delete those files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha! makes sense

await next( context );
},
System.CommandLine.Invocation.MiddlewareOrder.ExceptionHandler + 1
Expand Down