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

NAS-132372 / 25.04 / Add /dev/zvol root for explorer #11106

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[tooltip]="helptext.source_path_tooltip | translate"
[required]="true"
[multiple]="false"
[root]="'/'"
[nodeProvider]="fileNodeProvider"
></ix-explorer>
</ix-fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ export class CloudBackupFormComponent implements OnInit {
}

private setFileNodeProvider(): void {
this.fileNodeProvider = this.filesystemService.getFilesystemNodeProvider({ directoriesOnly: true });
this.fileNodeProvider = this.filesystemService.getFilesystemNodeProvider({
datasetsAndZvols: true,
});
}

private setBucketNodeProvider(): void {
Expand Down
47 changes: 39 additions & 8 deletions src/app/services/filesystem.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { Injectable } from '@angular/core';
import { map } from 'rxjs';
import {
catchError, map, of, throwError,
} from 'rxjs';
import { ExplorerNodeType } from 'app/enums/explorer-type.enum';
import { FileAttribute } from 'app/enums/file-attribute.enum';
import { FileType } from 'app/enums/file-type.enum';
import { ApiError } from 'app/interfaces/api-error.interface';
import { FileRecord } from 'app/interfaces/file-record.interface';
import { QueryFilter, QueryOptions } from 'app/interfaces/query-api.interface';
import { ExplorerNodeData, TreeNode } from 'app/interfaces/tree-node.interface';
import { TreeNodeProvider } from 'app/modules/forms/ix-forms/components/ix-explorer/tree-node-provider.interface';
import { ApiService } from 'app/services/websocket/api.service';

export interface ProviderOptions {
directoriesOnly?: boolean;
showHiddenFiles?: boolean;
includeSnapshots?: boolean;
datasetsAndZvols?: boolean;
}
@Injectable({ providedIn: 'root' })
export class FilesystemService {
constructor(
Expand All @@ -18,19 +27,34 @@ export class FilesystemService {
/**
* Returns a pre-configured node provider for files and directories.
*/
getFilesystemNodeProvider(providerOptions?: {
directoriesOnly?: boolean;
showHiddenFiles?: boolean;
includeSnapshots?: boolean;
}): TreeNodeProvider {
const options = {
getFilesystemNodeProvider(providerOptions?: ProviderOptions): TreeNodeProvider {
const options: ProviderOptions = {
directoriesOnly: false,
showHiddenFiles: false,
includeSnapshots: true,
datasetsAndZvols: false,
...providerOptions,
};

return (node: TreeNode<ExplorerNodeData>) => {
if (options.datasetsAndZvols) {
if (node.data.path.trim() === '/') {
return of([
{
path: '/mnt',
name: '/mnt',
hasChildren: true,
type: ExplorerNodeType.Directory,
},
{
path: '/dev/zvol',
name: '/dev/zvol',
hasChildren: true,
type: ExplorerNodeType.Directory,
},
] as ExplorerNodeData[]);
}
}
const typeFilter: [QueryFilter<FileRecord>?] = [];
if (options.directoriesOnly) {
typeFilter.push(['type', '=', FileType.Directory]);
Expand All @@ -47,10 +71,11 @@ export class FilesystemService {
};

return this.api.call('filesystem.listdir', [node.data.path, typeFilter, queryOptions]).pipe(

map((files) => {
const children: ExplorerNodeData[] = [];
files.forEach((file) => {
if (file.type === FileType.Symlink || !file.hasOwnProperty('name')) {
if ((!options.datasetsAndZvols && file.type === FileType.Symlink) || !file.hasOwnProperty('name')) {
return;
}

Expand All @@ -70,6 +95,12 @@ export class FilesystemService {

return children;
}),
catchError((error: ApiError) => {
if (error.reason === '[ENOENT] Directory /dev/zvol does not exist') {
return of([]);
}
return throwError(() => (error));
}),
);
};
}
Expand Down
Loading