File tree Expand file tree Collapse file tree 4 files changed +29
-8
lines changed Expand file tree Collapse file tree 4 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ export default class PuterFSProvider {
112112 capabilities . READDIR_UUID_MODE ,
113113
114114 capabilities . COPY_TREE ,
115+ capabilities . GET_RECURSIVE_SIZE ,
115116
116117 capabilities . READ ,
117118 capabilities . WRITE ,
@@ -777,6 +778,27 @@ export default class PuterFSProvider {
777778 return node ;
778779 }
779780
781+ async get_recursive_size ( { node } ) {
782+ const uuid = await node . get ( 'uid' ) ;
783+ const cte_query = `
784+ WITH RECURSIVE descendant_cte AS (
785+ SELECT uuid, parent_uid, size
786+ FROM fsentries
787+ WHERE parent_uid = ?
788+
789+ UNION ALL
790+
791+ SELECT f.uuid, f.parent_uid, f.size
792+ FROM fsentries f
793+ INNER JOIN descendant_cte d
794+ ON f.parent_uid = d.uuid
795+ )
796+ SELECT SUM(size) AS total_size FROM descendant_cte
797+ ` ;
798+ const rows = await db . read ( cte_query , [ uuid ] ) ;
799+ return rows [ 0 ] . total_size ;
800+ }
801+
780802 /**
781803 * @param {Object } param
782804 * @param {File } param.file: The file to write.
Original file line number Diff line number Diff line change @@ -536,15 +536,13 @@ module.exports = class FSNodeContext {
536536 * already fetched.
537537 */
538538 async fetchSize ( ) {
539- const { fsEntryService } = Context . get ( 'services' ) . values ;
540-
541539 // we already have the size for files
542540 if ( ! this . entry . is_dir ) {
543541 await this . fetchEntry ( ) ;
544542 return this . entry . size ;
545543 }
546544
547- this . entry . size = await fsEntryService . get_recursive_size ( this . entry . uuid ) ;
545+ this . entry . size = await this . provider . get_recursive_size ( { node : this } ) ;
548546
549547 return this . entry . size ;
550548 }
Original file line number Diff line number Diff line change 11/*
22 * Copyright (C) 2024-present Puter Technologies Inc.
3- *
3+ *
44 * This file is part of Puter.
5- *
5+ *
66 * Puter is free software: you can redistribute it and/or modify
77 * it under the terms of the GNU Affero General Public License as published
88 * by the Free Software Foundation, either version 3 of the License, or
99 * (at your option) any later version.
10- *
10+ *
1111 * This program is distributed in the hope that it will be useful,
1212 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1313 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414 * GNU Affero General Public License for more details.
15- *
15+ *
1616 * You should have received a copy of the GNU Affero General Public License
1717 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1818 */
@@ -35,6 +35,7 @@ const capabilityNames = [
3535 'copy-tree' ,
3636 'move-tree' ,
3737 'remove-tree' ,
38+ 'get-recursive-size' ,
3839
3940 // Behavior Capabilities
4041 'case-sensitive' ,
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ class SizeService extends BaseService {
108108 let sz ;
109109 if ( node . entry . is_dir ) {
110110 if ( node . entry . uuid ) {
111- sz = await fsEntryService . get_recursive_size ( node . entry . uuid ) ;
111+ sz = await node . fetchSize ( ) ;
112112 } else {
113113 // very unlikely, but a warning is better than a throw right now
114114 // TODO: remove this once we're sure this is never hit
You can’t perform that action at this time.
0 commit comments