(ctx context.Context, client *daggerClient)
| 1817 | } |
| 1818 | |
| 1819 | func (srv *Server) flushWorkspaceLocks(ctx context.Context, client *daggerClient) error { |
| 1820 | sess := client.daggerSession |
| 1821 | |
| 1822 | type pendingWorkspaceLockExport struct { |
| 1823 | ws *core.Workspace |
| 1824 | lockPath string |
| 1825 | delta *workspace.Lock |
| 1826 | } |
| 1827 | |
| 1828 | var pending []pendingWorkspaceLockExport |
| 1829 | |
| 1830 | sess.lockFileMu.RLock() |
| 1831 | for _, state := range sess.lockFiles { |
| 1832 | if state == nil || !state.loaded || !state.dirty { |
| 1833 | continue |
| 1834 | } |
| 1835 | delta, err := state.delta.Clone() |
| 1836 | if err != nil { |
| 1837 | sess.lockFileMu.RUnlock() |
| 1838 | return fmt.Errorf("clone workspace lock delta for %s: %w", state.lockPath, err) |
| 1839 | } |
| 1840 | if state.ws.ClientID == client.clientID { |
| 1841 | pending = append(pending, pendingWorkspaceLockExport{ |
| 1842 | ws: state.ws.Clone(), |
| 1843 | lockPath: state.lockPath, |
| 1844 | delta: delta, |
| 1845 | }) |
| 1846 | } |
| 1847 | } |
| 1848 | sess.lockFileMu.RUnlock() |
| 1849 | |
| 1850 | var flushErr error |
| 1851 | for _, export := range pending { |
| 1852 | srv.locker.Lock(export.lockPath) |
| 1853 | |
| 1854 | workspaceCtx, bk, err := srv.workspaceOwnerAccess(ctx, sess, export.ws) |
| 1855 | if err == nil { |
| 1856 | var latest *workspace.Lock |
| 1857 | latest, err = readWorkspaceLockState(workspaceCtx, bk, export.ws) |
| 1858 | if err == nil { |
| 1859 | err = latest.Merge(export.delta) |
| 1860 | } |
| 1861 | if err == nil { |
| 1862 | err = exportWorkspaceLockToHost(workspaceCtx, bk, export.ws, latest) |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | srv.locker.Unlock(export.lockPath) |
| 1867 | |
| 1868 | if err != nil { |
| 1869 | flushErr = errors.Join(flushErr, fmt.Errorf("flush workspace lock %s: %w", export.lockPath, err)) |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | return flushErr |
| 1874 | } |
| 1875 | |
| 1876 | // If the current client is coming from a function, return the module that function is from |
no test coverage detected