Skip to content

Commit

Permalink
Re-use basename from cockpit's new path lib
Browse files Browse the repository at this point in the history
Drop our own implementation in favour of the shared cockpit-lib one.
  • Loading branch information
jelly authored and martinpitt committed Sep 19, 2024
1 parent 2f0919c commit 01773e4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 17 deletions.
13 changes: 0 additions & 13 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,3 @@ export function * map_permissions<T>(func: (value: number, label: string) => T)
yield func(value, label);
}
}

export function basename(path: string) {
if (path === '/') {
return path;
}

const elements = path.replace(/\/$/, '').split('/');
if (elements.length === 0) {
return '/';
} else {
return elements[elements.length - 1];
}
}
3 changes: 2 additions & 1 deletion src/dialogs/permissions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import { Stack } from '@patternfly/react-core/dist/esm/layouts/Stack';

import cockpit from 'cockpit';
import { InlineNotification } from 'cockpit-components-inline-notification';
import { basename } from "cockpit-path";
import { useInit } from 'hooks';
import { etc_group_syntax, etc_passwd_syntax } from 'pam_user_parser';
import { superuser } from 'superuser';

import { useFilesContext } from '../app.tsx';
import { map_permissions, inode_types, basename } from '../common.ts';
import { map_permissions, inode_types } from '../common.ts';

const _ = cockpit.gettext;

Expand Down
2 changes: 1 addition & 1 deletion src/files-breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import { Tooltip, TooltipPosition } from "@patternfly/react-core/dist/esm/compon
import { CheckIcon, OutlinedHddIcon, PencilAltIcon, StarIcon, TimesIcon } from "@patternfly/react-icons";

import cockpit from "cockpit";
import { basename } from "cockpit-path";
import { useInit } from "hooks";

import { useFilesContext } from "./app.tsx";
import { basename } from "./common.ts";

const _ = cockpit.gettext;

Expand Down
2 changes: 1 addition & 1 deletion src/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { AlertVariant } from "@patternfly/react-core/dist/esm/components/Alert";

import cockpit from "cockpit";
import type { FileInfo } from "cockpit/fsinfo";
import { basename } from "cockpit-path";
import type { Dialogs } from 'dialogs';

import type { FolderFileInfo } from "./app";
import { basename } from "./common.ts";
import { confirm_delete } from './dialogs/delete.tsx';
import { edit_file, MAX_EDITOR_FILE_SIZE } from './dialogs/editor.tsx';
import { show_create_directory_dialog } from './dialogs/mkdir.tsx';
Expand Down
3 changes: 2 additions & 1 deletion src/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import { Text, TextContent, TextVariants } from "@patternfly/react-core/dist/esm

import cockpit from "cockpit";
import { KebabDropdown } from "cockpit-components-dropdown";
import { basename } from "cockpit-path";
import { useDialogs } from "dialogs";
import * as timeformat from "timeformat";

import { FolderFileInfo, useFilesContext } from "./app.tsx";
import { basename, get_permissions } from "./common.ts";
import { get_permissions } from "./common.ts";
import { edit_permissions } from "./dialogs/permissions.jsx";
import { get_menu_items } from "./menu.tsx";

Expand Down

0 comments on commit 01773e4

Please sign in to comment.